Mayday, mayday

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • confusedandinsane
    New Member
    • Sep 2006
    • 6

    Mayday, mayday

    I am trying to write this short program that will calculate, (1) the cost for hotel (45 a night), cost for gas (1.67 a gallon) and total cost. The car is going to be used for a total of 200 and it already 20 miles on it. I know that 200/20*1.67 is the correct formula but how would I get the visual 6.00C++ to recognize it.
    Here is what I have so far:

    #include<iostre am>
    #include<iomani p>

    using namespace std;

    int main()

    {
    int num
    int destination;
    double total;
    const double hotel = 45.00


    cout<<"Welcome to Oscar Vacation Planner!\n"<<en dl;
    cout<<"Please enter destination distance"<<endl ;
    cin>> destination;

    cout<<"Enter your cars mileage"<<endl;
    cin>> mileage;

    cout<<"Enter cost of gas per gallon"<<endl;
    cin>> gas;


    cout<<"How many days are you staying"<<endl;
    total = hotel * 2;

    total = destination * mileage /gas;
    total = hotel * 2;

    /*
    gas 1.67
    hotel 45.00

    */





    cout<< fixed<<showpoin t;
    cout<<setprecis ion(2);




    cout<<setw(20)< <"Total:";
    cout<<setw(10)< <total<<endl;

    return 0;
    }
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You want to add your 2 totals

    Code:
    cout<<"How many days are you staying"<<endl;
    total = hotel * 2;  // <-- oops number of days hard coded to 2
    
    total = destination * mileage /gas;  // <-- This overwrites the hotel total
    total = hotel * 2;      // <-- This overwrites the car total
    You need to add the totals instead like this

    Code:
    int days;  // Put this at the top of the function
    
    cout<<"How many days are you staying"<<endl;
    cin >> days;
    total = hotel * days;
    
    total += destination * mileage /gas;  // Add car total onto hotel total

    Comment

    • confusedandinsane
      New Member
      • Sep 2006
      • 6

      #3
      I have added the set of code you gave me and along with my code. I am still getting a error message. This is the new error I am receiving, and it is the only one. Can you please take a look at it.



      C:\Program Files\Microsoft Visual Studio\MyProjec ts\webscript\ba nta.cpp(7) : error C2447: missing function header (old-style formal list?)


      Originally posted by Banfa
      You want to add your 2 totals

      Code:
      cout<<"How many days are you staying"<<endl;
      total = hotel * 2;  // <-- oops number of days hard coded to 2
      
      total = destination * mileage /gas;  // <-- This overwrites the hotel total
      total = hotel * 2;      // <-- This overwrites the car total
      You need to add the totals instead like this

      Code:
      int days;  // Put this at the top of the function
      
      cout<<"How many days are you staying"<<endl;
      cin >> days;
      total = hotel * days;
      
      total += destination * mileage /gas;  // Add car total onto hotel total

      Comment

      Working...