It is supposed to look like this but for some reason when I enter (total) my code just stops. Im not really sure what I am doing wrong. I know this is a big question to ask but all help is appreciated
The estimated miles driven per year: 15000
The estimated price of a gallon of gas during the 5 years of ownership: -4.53
I'm sorry, you must enter a value bigger than zero. Please try again. Please enter:
The estimated price of a gallon of gas during the 5 years of ownership: 4.53
The initial cost of a hybrid car: 28000
The efficiency of the hybrid car in miles per gallon: 46.5
The estimated resale value (a dollar amount) for a hybrid after 5 years: 16000
The initial cost of a non-hybrid car: 0
I'm sorry, you must enter a value bigger than zero. Please try again. Please enter:
The initial cost of a non-hybrid car: 24000
The efficiency of the non-hybrid car in miles per gallon: 28.5
The estimated resale value (a dollar amount) for a non-hybrid after 5 years: 12000
The user's buying criterion, either minimized gas consumption or total cost (enter Gas or Total): Total
For the Hybrid Car:
The total gallons of fuel consumed over 5 years: 1612.90
The total cost of owning the car for 5 years: 19306.45
For the NON-Hybrid Car:
The total gallons of fuel consumed over 5 years: 2631.58
The total cost of owning the car for 5 years: 23921.05
cout << "The estimated miles driven per year: "; //Miles driven per year
double miles_per_year;
cin >> miles_per_year;
if (miles_per_year <= 0)
{
cout << "Please enter a positive number: ";
cin >> miles_per_year;
}
cout << "Please enter the estimated price of a gallon during the 5 years of ownership: "; // Price per gallon over 5 years
double price_per_gallon;
cin >> price_per_gallon;
if (price_per_gallon <= 0)
{
cout << "Please enter a positive number: ";
cin >> price_per_gallon;
}
cout << "The initial cost of a hybrid car: ";// initial price of hybrid car
double price_hybrid;
cin >> price_hybrid;
if (price_hybrid <= 0)
{
cout << "Please enter a positive number: ";
cin >> price_hybrid;
}
cout << "The efficiency of the hybrid car in miles per gallon: ";// efficiency of the hybrid car in miles per gallon
double efficiency_hybrid;
cin >> efficiency_hybrid;
if (efficiency_hybrid <= 0)
{
cout << "Please enter a positive number: ";
cin >> efficiency_hybrid;
}
cout << "The estimated resale value (a dollar amount) for a hybrid after 5 years: ";// estimated resale value of the hybrid car after 5 years
double resale_hybrid;
cin >> resale_hybrid;
if (resale_hybrid <= 0)
{
cout << "Please enter a positive number: ";
cin >> resale_hybrid;
}
cout << "The initial cost of a non-hybrid car: ";// initial price of non-hybrid car
double price_non_hybrid;
cin >> price_non_hybrid;
if (price_non_hybrid <= 0)
{
cout << "Please enter a positive number: ";
cin >> price_non_hybrid;
}
cout << "The efficiency of the non-hybrid car in miles per gallon: ";// efficiency of non-hybrid car
double efficiency_non_hybrid;
cin >> efficiency_non_hybrid;
if (efficiency_non_hybrid <= 0)
{
cout << "Please enter a positive number: ";
cin >> efficiency_non_hybrid;
}
cout << "The estimated resale value (a dollar amount) for a non-hybrid after 5 years: ";// resale of non-hybrid car
double resale_non_hybrid;
cin >> resale_non_hybrid;
if (resale_non_hybrid <= 0)
{
cout << "Please enter a positive number: ";
cin >> resale_non_hybrid;
}
string buyer_criterion; //buyer criterion input
cout << "Minimized gas or minimized total cost (enter \"Gas\" or \"Total\"): ";
cin >> buyer_criterion;
}
else if (buyer_criterion == "Total")
{
if (total_cost_hybrid <= total_cost_non_hybrid)
{
cout << "For the Hybrid Car: " << endl;
cout << "The total gallons of fuel consumed over 5 years: " << total_gallons_hybrid << endl;
cout << "The total cost of owning the car for 5 years: " << total_cost_hybrid << endl;
You're program worked fine for me. I used all the inputs you show in your question, and it was fine. So, I'm thinking that you entered "total", and NOT "Total", with a capital 'T'