I can't get the loops right. It does it a different way every time & i need to add a third loop if they input invalid miles.

#include <iostream>
using namespace std;


double computeVehicleCost(double overageRate, int freeMiles, double dailyFee, int estimatedMiles);
int main()
{


const double CLASS_E_DAILY_FEE = 45.90;
const int CLASS_E_FREE_MILES = 40;
const double CLASS_E_OVERAGE_RATE = 0.25;
const double CLASS_S_DAILY_FEE = 57.75;
const int CLASS_S_FREE_MILES = 120;
const double CLASS_S_OVERAGE_RATE = 0.40;
const double CLASS_L_DAILY_FEE = 85.50;
const int CLASS_L_FREE_MILES = 200;
const double CLASS_L_OVERAGE_RATE = 0.50;
const double CLASS_V_DAILY_FEE = 55.00;
const int CLASS_V_FREE_MILES = 150;
const double CLASS_V_OVERAGE_RATE = 0.50;
const double CLASS_T_DAILY_FEE = 55.00;
const int CLASS_T_FREE_MILES = 150;
const double CLASS_T_OVERAGE_RATE = 0.50;


int estimatedMiles, a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z;
char classOfVehicle, anotherQuote;
double selectedVehicleCost, eCost, sCost, lCost, vCost, tCost;
bool run=true;
bool go=true;

while(run)
{


cout << "Enter the class of the vehicle. E for economy, S for Sport, L for luxury, V for van, or T for truck: ";
cin >> classOfVehicle;



if (classOfVehicle == a,b,c,d,f,g,h,i,j,k,m,n,o,p,q,r,u,w,x,y,z || classOfVehicle == A,B,C,D,F,G,H,I,J,K,M,N,O,P,Q,R,U,W,X,Y,Z)
{
go=false;


cout << "Invalid input please enter E for economy, S for Sport, L for luxury, V for van, or T for truck: ";
cin >> classOfVehicle; }

else; {go=true;
}



cout << "Please enter the estimated miles (1 to 812): ";
cin >> estimatedMiles;

eCost = computeVehicleCost(CLASS_E_OVERAGE_RATE, CLASS_E_FREE_MILES, CLASS_E_DAILY_FEE, estimatedMiles);
lCost = computeVehicleCost(CLASS_L_OVERAGE_RATE, CLASS_L_FREE_MILES, CLASS_L_DAILY_FEE, estimatedMiles);
sCost = computeVehicleCost(CLASS_S_OVERAGE_RATE, CLASS_S_FREE_MILES, CLASS_S_DAILY_FEE, estimatedMiles);
vCost = computeVehicleCost(CLASS_V_OVERAGE_RATE, CLASS_V_FREE_MILES, CLASS_V_DAILY_FEE, estimatedMiles);
tCost = computeVehicleCost(CLASS_T_OVERAGE_RATE, CLASS_T_FREE_MILES, CLASS_T_DAILY_FEE, estimatedMiles);

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);


switch (classOfVehicle)
{
case 'E':
case 'e':
cout << "Economy vehicle cost: $" << eCost << endl;
selectedVehicleCost = eCost;
break;
case 'S':
case 's':
cout << "Sport vehicle cost: $" << sCost << endl;
selectedVehicleCost = sCost;
break;
case 'L':
case 'l':
cout << "Luxury vehicle cost: $" << lCost << endl;
selectedVehicleCost = lCost;
break;
case 'V':
case 'v':
cout << "Van vehicle cost: $" << vCost << endl;
selectedVehicleCost = vCost;
break;
case 'T':
case 't':
cout << "Truck vehicle cost: $" << tCost << endl;
selectedVehicleCost = tCost;
break;
}

if (eCost < selectedVehicleCost)
{
cout << "Economy is cheaper by: $" << selectedVehicleCost - eCost << endl;
}
if (sCost < selectedVehicleCost)
{
cout << "Sport is cheaper by: $" << selectedVehicleCost - sCost << endl;
}
if (lCost < selectedVehicleCost)
{
cout << "Luxury is cheaper by: $" << selectedVehicleCost - lCost << endl;
}
if (vCost < selectedVehicleCost)
{
cout << "Van is cheaper by: $" << selectedVehicleCost - vCost << endl;
}
if (tCost < selectedVehicleCost)
{
cout << "Truck is cheaper by: $" << selectedVehicleCost - tCost << endl;
}


cout << "Would you like another quote. Press Y for yes and N for no: ";
cin >> anotherQuote;

if(anotherQuote =='N'||anotherQuote =='n'){
run = false;}
else (anotherQuote == a,b,c,d,e,f,g,h,i,j,k,l,m,o,p,q,r,s,t,u,v,w,x,z || anotherQuote == A,B,C,D,E,F,G,H,I,J,K,L,M,O,P,Q,R,S,T,U,V,W,Z);
{
run = false;
cout << "Invalid input. Would you like another quote. Press Y for yes N for no: ";
cin >> anotherQuote;
}
if(anotherQuote =='N'||anotherQuote =='n'){
run = false;}

}
return 0;
}



double computeVehicleCost(double overageRate, int freeMiles, double dailyFee, int estimatedMiles)

{
double vehicleCost = dailyFee;

if (estimatedMiles > freeMiles)
{
vehicleCost += (estimatedMiles - freeMiles) * overageRate;
}
return vehicleCost;
}
help us help you.
explain exactly what you need.
use code tags.

you have a jillion integers with no initial value that you are making a mess with.
the letter a when typed by a user is 'a'.
int a; //a random value
if(x == a)//meaningless, a is random.

you want something like
if x is between a-z or A-Z which looks like this:
if( x >='a' && x <= 'z') || (x >='A' && x<='Z'))
I think. Its a bit hard to mind read what you want, but taking a guess.
there is a built in test if something is an ascii letter.
the above is the same as if(isalpha(x))
double quotes are strings, single quotes are letters, when coding literal values.
Last edited on
Topic archived. No new replies allowed.