Thread: Issue with calculations

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    23

    Issue with calculations

    Hey guys I had an issue with some of the calculations they are not seeming to coming out correctly.

    Program I was asked to write:
    Problem Specification Hillside Rent-AllThe Hillside Rent-All Company requires a program that can generate an invoice for the rental of one ofits items (note that an item cannot be rented for a fraction of a day). The invoice should include thecurrent date, customer's name, item description, and all of the information that is required to computethe total cost and the balance due.The company uses the following equations to determine the costs:Rental Cost: Base Rental Cost + Cost Per Day x Number of DaysTax: 7% of the Rental CostTotal Cost: Rental Cost + TaxSecurity Deposit: 10% of the Total CostBalance Due: Total Cost - Security Deposit

    Input data will be- the date that you enter the data- your name for the customer- Base Cost, Daily Cost, and Days




    Code:
    #include <iostream> // Required #include for running program#include <fstream>
    #include <string>
    #include <iomanip>
    #include <fstream>
    
    int main()
    {
    
    
    using namespace std;
    const double SALES_TAX = .07; //constant values of sales tax
    const double SECURITY_DEPOSIT = .10; // constant value of the security deposit required for renting equipment
     
    string cust_name;
    int month;
    int day;
    int year;
    int days_rented;
    double rental_cost;
    double base_cost;
    double total_cost;
    double daily_cost;
    double security_total;
    double balance_due;
    double item_tax;
    
    
    //Inputs of the date / customer name / Number of rented days 
    cout << "Please Enter the month: ";
    cin >> month; 
    
    
    cout << "Please Enter the day: ";
    cin >> day;
    
    
    cout << "Please Enter the year: ";
    cin >> year;
    cin.ignore(8, '\n');
    
    
    cout << "Please enter your full name: ";
    getline(cin, cust_name);
    
    
    cout << "Please enter the number of days you wish to rent the item: ";
    cin >> days_rented;
    
    
    cout << "Please enter the Daily cost of the item you are renting:";
    cin >> daily_cost;
    
    
    cout << "Please enter the Base cost of the item:";
    cin >> base_cost;
    
    
    //Rental cost 
    rental_cost = base_cost + daily_cost * days_rented;
    
    
    //total cost
    total_cost = rental_cost * SALES_TAX;
    
    
    //Security Deposit
    security_total = total_cost * SECURITY_DEPOSIT;
    
    
    // Tax amount
    item_tax = SALES_TAX * total_cost;
    
    
    //Balance left after security deposit
    balance_due = total_cost - security_total;
    
    
    cout << "Hillside Rent-All Company" << endl;
    
    
    cout << "Date: " << month << "/" << day << "/" << year << endl;
    
    
    cout << "Customer Name: " << cust_name << endl;
    
    
    cout << "Item: Snow Blower" << endl;
    
    
    cout << "Base Cost: " << base_cost << endl;
    
    
    cout << "Daily Cost: " << daily_cost << endl;
    
    
    cout << "Rental Cost: " << rental_cost << endl;
    
    
    cout << "Tax Amount: " << item_tax << endl;
    
    
    cout << "Total Cost: " << total_cost << endl;
    
    
    cout << " Security Deposit: " << security_total << endl;
    
    
    cout << "Balance Due: " << balance_due << endl;
    
    
    return 0;
    Output:
    Please Enter the month: 5
    Please Enter the day: 5
    Please Enter the year: 5
    Please enter your full name: Joe
    Please enter the number of days you wish to rent the item: 5
    Please enter the Daily cost of the item you are renting:5
    Please enter the Base cost of the item:50
    Hillside Rent-All Company
    Date: 5/5/5
    Customer Name: Joe
    Item: Snow Blower
    Base Cost: 50
    Daily Cost: 5
    Rental Cost: 75
    Tax Amount: 0.3675
    Total Cost: 5.25
    Security Deposit: 0.525
    Balance Due: 4.725


    --------------------------------
    Process exited after 11.14 seconds with return value 0
    Press any key to continue . . .


    Thank you in advanced this forum has been nothing but helpful to me.
    Last edited by Pastryking; 10-20-2016 at 10:59 AM.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Hey guys I had an issue with some of the calculations they are not seeming to coming out correctly.
    What calculations?

    Please show what you expect the output to be with the given input.

    Jim

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    You calculated sales tax twice.
    Code:
    total_cost = rental_cost * SALES_TAX;
    item_tax = SALES_TAX * total_cost;

  4. #4
    Registered User
    Join Date
    Oct 2016
    Posts
    23
    Quote Originally Posted by jimblumberg View Post
    What calculations?

    Please show what you expect the output to be with the given input.

    Jim
    It's based on the computation, but to be more specific the total cost, tax amount, balance due, and security deposit are wrong. So based on current output posted those should be based on 75 the rental cost. Which comes out correct.

  5. #5
    Registered User
    Join Date
    Oct 2016
    Posts
    23
    Quote Originally Posted by whiteflags View Post
    You calculated sales tax twice.
    Code:
    total_cost = rental_cost * SALES_TAX;
    item_tax = SALES_TAX * total_cost;
    That is done intentionally unless I am coding That part incorrectly. They are two different number totals.

  6. #6
    Registered User
    Join Date
    Oct 2016
    Posts
    23
    Quote Originally Posted by Pastryking View Post
    That is done intentionally unless I am coding That part incorrectly. They are two different number totals.
    Ignore this post you fixed my issue sorry for the inconvenience silly error on my part.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calculations Issue
    By dhuan in forum C++ Programming
    Replies: 1
    Last Post: 12-02-2010, 08:36 PM
  2. Calculations
    By bumfluff in forum C++ Programming
    Replies: 7
    Last Post: 11-09-2005, 10:01 AM
  3. pi calculations
    By nbice in forum C++ Programming
    Replies: 7
    Last Post: 09-30-2002, 01:48 PM
  4. calculations
    By wayko in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2001, 10:44 AM

Tags for this Thread