# Solved about : write a c++ program calculating

October 8, 2012 at 12:15:12
Specs: Windows 7
 THE QUESTION ASK ME THIS :write a program that calculates and prints the bills cost in a restaurant by reading the meals cost and number of people ordered this meal from the user and i answered in the program like this :#include using namespace std;int main (){ int meal cost,number of people ordered this meal; float bill cost; cout<<"Enter meal cost"; cin>>meal cost; cout<<"Enter the number of people ordered this meal"; cin>>number of people ordered this meal; bill cost=meal cost*number of people ordered this meal; cout<<"bill cost = "<

See More: about : write a c++ program calculating

#1
October 8, 2012 at 14:12:09
 Variable names can't contain spaces.

Report •

#2
October 8, 2012 at 14:35:46
 Here you go (just began learning c++ and love it),#include int main(){using std::cout;using std::cin;float a, b, c;cout << "Enter meal cost and the number of people who ordered this meal seperated by a space each\n";cin >> a;cin >> b;c=a * b;cout <<"Bill cost is:" << c << "\n";return 0;}

Report •

#3
October 8, 2012 at 14:43:48
 At least the OP used meaningful variable names (albeit illegal). Never just use single letters for variables (well, hardly ever); it makes it nigh on impossible to maintain the program a few months down the line.Get into the habit of using variable names that mean something. Note that whilst "number of people that ordered meal" is not a valid variable name "number_of_people_that_ordered_meal" and "numberOfPeopleThatOrderedMeal" both are valid. But they are probably a bit long. Perhaps "numberWhoOrdered" would be better.Also note that as "numberWhoOrdered" and "mealCost" are both integers there is no point in making "billCost" a float. The only result of that is that you lose a little precision in the answer.

Report •

Related Solutions

#4
October 8, 2012 at 15:21:28
 Thank you all for your cooperation with me :) <3

Report •