I am starting a c++ class soon and have been reading over my textbook and decided to try a simple program. I attempted to write a simple gas calculator and from what I have studied believed it would work. Unforturnatley when I run the program after I type in and answer the first question it shuts down right away. If anyone could help that would be great.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int tank_size, estimated_mpg;
double price_of_gas, fill_up_cost, miles_on_tank;
string car_model;
cout << "Press enter after answering\n";
cout << "What type of vehicle do you own?\n";
cin >> car_model;
cout << "What is your tank size?\n";
cin >> tank_size;
cout << "What is the price of a gallon of gas?\n";
cin >> price_of_gas;
cout << "What is your estimated mpg?\n";
cin >> estimated_mpg;
fill_up_cost = price_of_gas * tank_size;
miles_on_tank = tank_size * estimated_mpg;
cout << "Your" << car_model << "costs" << fill_up_cost << "\n";
cout << "dollars to fill and will recieve" << miles_on_tank << "miles on a full tank";
I don't actually know the answer, but I'm not sure kloid and eidge have answered it either
Unforturnatley when I run the program after I type in and answer the first question it shuts down right away
After he answers the first question, the console window would stay open to wait for the answer for the second question, so it doesn't seem to be just as simple as the console window closing after the program has finished.
I compiled your program, and it worked correctly, as long as I only entered a single name for the vehicle model. If I enter, for instance, 'Ford Pinto', the program drops through to the end, with some strange ending calculations. Does it shut down completely even if you enter a single word?
Hey gets thanks for the help. I did realize that if I enter one word for the vehicle model it will continue and ask the other questions, however it shuts down at the end still.