Here is my code so far. I just can't get the last 3 lines. I need to accept only text that says Total or Gas. How would I do that? I've looked up and read a lot of stuff but everything I tries doesn't work haha. any help would be great.
Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
int miles_per_year;
double gallon_gas;
double hybrid_cost;
int hybrid_mpg;
double hybrid_resale;
double cost_nonhybrid;
int non_hybrid_mpg;
double nonhybrid_resale;
int buying_crit;
cout <<"Please answer the following questions.\n" << endl;
do
{
cout <<"The estimated miles driven per year?" << endl;
cin >> miles_per_year;
if(miles_per_year < 0)
cout <<"Please enter a positive value." << endl;
} while(miles_per_year < 0);
do
{
cout <<"The estimated price of a gallon of gas?" << endl;
cin >> gallon_gas;
if(gallon_gas < 0)
cout <<"Please enter a positive value." << endl;
} while(gallon_gas < 0);
do
{
cout <<"The cost of a hybrid car?" << endl;
cin >> hybrid_cost;
if(hybrid_cost < 0)
cout <<"Please enter a positive value." << endl;
} while(hybrid_cost < 0);
do
{
cout <<"The efficiency of the hybrid car in miles per gallon?" << endl;
cin >> hybrid_mpg;
if(hybrid_mpg < 0)
cout <<"Please enter a positive value." << endl;
} while(hybrid_mpg < 0);
do
{
cout <<"The estimated resale value for a hybrid after 5 years?" << endl;
cin >> hybrid_resale;
if(hybrid_resale < 0)
cout <<"Please enter a positive value." << endl;
} while(hybrid_resale < 0);
do
{
cout <<"The cost of a non-hybrid car?" << endl;
cin >> cost_nonhybrid;
if(cost_nonhybrid < 0)
cout <<"Please enter a positive value." << endl;
} while(cost_nonhybrid < 0);
do
{
cout <<"The efficiency of the non-hybrid car in miles per gallon?" << endl;
cin >> non_hybrid_mpg;
if(non_hybrid_mpg < 0)
cout <<"Please enter a positive value." << endl;
} while(non_hybrid_mpg < 0);
do
{
cout <<"The estimated resale value for a non-hybrid after 5 years?" << endl;
cin >> nonhybrid_resale;
if(nonhybrid_resale < 0)
cout <<"Please enter a positive value." << endl;
} while(nonhybrid_resale < 0);
cout <<"Would you like results sorted by lowest gas consumption(\"gas\")\n or lowest total cost(\"total\")?" << endl;
cout <<"Please enter either \"gas\" or \"total\" for how results are to be sorted." << endl;
cin >> buying_crit;
system("pause");
return 0;
}