#include%26lt;iostream%26gt;
#include%26lt;iomanip%26gt;
#include%26lt;fstream%26gt;
#include%26lt;cstring%26gt;
using namespace std;
void GetRates(float%26amp;, float%26amp;, float%26amp;, float%26amp;);
enum Vehicles{MOTORCYCLE, CAR, BUS, TRUCK};
int main()
{
float cycleRate;
float carRate;
float busRate;
float truckRate;
char code;
int weight;
ifstream inFile;
bool invalidData;
inFile.open("vehicleCode.dat");
if(!inFile)
{
cout%26lt;%26lt;"Unable to open input file, program abnormally ended"%26lt;%26lt;endl;
return 1;
}
inFile%26gt;%26gt;code%26gt;%26gt;weight;
{
if(code=='m')
code=MOTORCYCLE;
else if(code=='c')
code=CAR;
else if(code=='b')
code=BUS;
else if(code=='t')
code=TRUCK;
else
cout%26lt;%26lt;"Error: Invalid Vehicle type";
}
if(100%26lt;=weight%26amp;%26amp;weight%26lt;=99000)
invalidData=false;
else
cout%26lt;%26lt;"Error:Invalid weight(non integer)";
Vehicles code;
switch(code)
{
case MOTORCYCLE:cout%26lt;%26lt;"MOTORCYCLE";
break;
case CAR:cout%26lt;%26lt;"CAR";
break;
case BUS:cout%26lt;%26lt;"BUS";
break;
case TRUCK:cout%26lt;%26lt;"TRUCK";
default:cout%26lt;%26lt;"Invalid vehicle type";
}
GetRates(cycleRate, carRate, busRate, truckRate);
cout%26lt;%26lt;"ROAD TAX REPORT"%26lt;%26lt;endl;
cout%26lt;%26lt;"Vehicle Type:"%26lt;%26lt;" Weight:"%26lt;%26lt;" Rate:"%26lt;%26lt;" Tax Due:"%26lt;%26lt;endl;
if(code=='m')
cout%26lt;%26lt;code%26lt;%26lt;weight%26lt;%26lt;cycleRate%26lt;%26lt;weight*...
else if(code=='c')
cout%26lt;%26lt;code%26lt;%26lt;weight%26lt;%26lt;carRate%26lt;%26lt;weight*ca...
else if(code=='b')
cout%26lt;%26lt;code%26lt;%26lt;weight%26lt;%26lt;busRate%26lt;%26lt;weight*bu...
else if (code=='t')
cout%26lt;%26lt;code%26lt;%26lt;weight%26lt;%26lt;truckRate%26lt;%26lt;weight*...
return 0;
}
void GetRates(/*out*/ float%26amp; motorcycleRate,
/*out*/ float%26amp; carsRate,
/*out*/ float%26amp; busesRate,
/*out*/ float%26amp; trucksRate)
{
bool invalidData;
invalidData=true;
while(invalidData)
{
cout%26lt;%26lt;"Enter the tax rate for MOTORCYCLES(0.01-0.99)"%26lt;%26lt;endl;
cin%26gt;%26gt;motorcycleRate;
{
if(0.009%26lt;=motorcycleRate%26amp;%26amp;motorcycleRate...
invalidData=false;
else
cout%26lt;%26lt;"Warning: entry invalid, rate must be between 0.01 and 0.99"%26lt;%26lt;endl;
}
}
invalidData=true;
while(invalidData)
{
cout%26lt;%26lt;"Enter the tax rate for CARS(0.01-0.99)"%26lt;%26lt;endl;
cin%26gt;%26gt;carsRate;
{
if(0.009%26lt;=carsRate%26amp;%26amp;carsRate%26lt;=0.999)
invalidData=false;
else
cout%26lt;%26lt;"Warning: entry invalid, rate must be between 0.01 and 0.99"%26lt;%26lt;endl;
}
}
invalidData=true;
while(invalidData)
{
cout%26lt;%26lt;"Enter the tax rate for BUSES(0.01-0.99)"%26lt;%26lt;endl;
cin%26gt;%26gt;busesRate;
{
if(0.009%26lt;=busesRate%26amp;%26amp;busesRate%26lt;=0.999)
invalidData=false;
else
cout%26lt;%26lt;"Warning: entry invalid, rate must be between 0.01 and 0.99"%26lt;%26lt;endl;
}
}
invalidData=true;
while(invalidData)
{
cout%26lt;%26lt;"Enter the tax rate for TRUCKS(0.01-0.99)"%26lt;%26lt;endl;
cin%26gt;%26gt;trucksRate;
{
if(0.009%26lt;=trucksRate%26amp;%26amp;trucksRate%26lt;=0.999)
invalidData=false;
else
cout%26lt;%26lt;"Warning: entry invalid, rate must be between 0.01 and 0.99"%26lt;%26lt;endl;
}
}
}
This prog is suppsed to read an input file containing records: vehicle code weight(codes are m,c and b)Help!!
Looks like the problem is your switch statement. Code is a char, but your switch is looking for cases using the full strings.
switch(code)
{
case MOTORCYCLE:cout%26lt;%26lt;"MOTORCYCLE";
break;
case CAR:cout%26lt;%26lt;"CAR";
break;
case BUS:cout%26lt;%26lt;"BUS";
break;
case TRUCK:cout%26lt;%26lt;"TRUCK";
default:cout%26lt;%26lt;"Invalid vehicle type";
}
should be like (mind the caps too, id convert em to be safe):
switch(code)
{
case M:cout%26lt;%26lt;"MOTORCYCLE";
break;
case C:cout%26lt;%26lt;"CAR";
break;
case B:cout%26lt;%26lt;"BUS";
break;
case T:cout%26lt;%26lt;"TRUCK";
default:cout%26lt;%26lt;"Invalid vehicle type";
}
Reply:What problems are you having, and make sure you aren't having capitalization problems on your data.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment