By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,035 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,035 IT Pros & Developers. It's quick & easy.

Mayday, mayday

P: 6
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<iostream>
#include<iomanip>

using namespace std;

int main()

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


cout<<"Welcome to Oscar Vacation Planner!\n"<<endl;
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<<showpoint;
cout<<setprecision(2);




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

return 0;
}
Sep 20 '06 #1
Share this Question
Share on Google+
2 Replies


Banfa
Expert Mod 5K+
P: 8,916
You want to add your 2 totals

Expand|Select|Wrap|Line Numbers
  1. cout<<"How many days are you staying"<<endl;
  2. total = hotel * 2;  // <-- oops number of days hard coded to 2
  3.  
  4. total = destination * mileage /gas;  // <-- This overwrites the hotel total
  5. total = hotel * 2;      // <-- This overwrites the car total
  6.  
You need to add the totals instead like this

Expand|Select|Wrap|Line Numbers
  1. int days;  // Put this at the top of the function
  2.  
  3. cout<<"How many days are you staying"<<endl;
  4. cin >> days;
  5. total = hotel * days;
  6.  
  7. total += destination * mileage /gas;  // Add car total onto hotel total
  8.  
Sep 21 '06 #2

P: 6
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\MyProjects\webscript\banta.cpp(7) : error C2447: missing function header (old-style formal list?)


You want to add your 2 totals

Expand|Select|Wrap|Line Numbers
  1. cout<<"How many days are you staying"<<endl;
  2. total = hotel * 2;  // <-- oops number of days hard coded to 2
  3.  
  4. total = destination * mileage /gas;  // <-- This overwrites the hotel total
  5. total = hotel * 2;      // <-- This overwrites the car total
  6.  
You need to add the totals instead like this

Expand|Select|Wrap|Line Numbers
  1. int days;  // Put this at the top of the function
  2.  
  3. cout<<"How many days are you staying"<<endl;
  4. cin >> days;
  5. total = hotel * days;
  6.  
  7. total += destination * mileage /gas;  // Add car total onto hotel total
  8.  
Sep 22 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.