English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

//Sample program to read input file and perform calculations with interactive values.
//Print out a table with input and calculated values.
#include
#include
#include
#include
using namespace std;

void GetRates(float&, float&, float&, float&);

enum Vehicles{MOTORCYCLE, CAR, BUS, TRUCK};



int main()

{
float cycleRate;
float carRate;
float busRate;
float truckRate;
char code;
int weight;
ifstream inFile;
Vehicles typeCode;



inFile.open("file1.dat");
if(!inFile)
{
cout<<"Unable to open input file, program abnormally ended"< return 1;
}

GetRates(cycleRate, carRate, busRate, truckRate);
cout< cout<
inFile>>code>>weight;

while(inFile)


{
if(code=='m')
typeCode=MOTORCYCLE;
else if(code=='c')
typeCode=CAR;
else if(code=='b')
typeCode=BUS;
else if(code=='t')
typeCode=TRUCK;
inFile>>code>>weight;

}

switch(typeCode)
{
case MOTORCYCLE:cout<<"MOTORCYCLE";
break;
case CAR:cout<<"CAR";
break;
case BUS:cout<<"BUS";
break;
case TRUCK:cout<<"TRUCK";
break;
default:cout<<"Error: Invalid Vehicle Type";

}

{
if(code=='m')
cout< else if (code=='c')
cout< else if(code=='b')
cout< else if(code=='t')
cout< else
cout< return 0;
}

}





void GetRates(/*out*/ float& motorcycleRate,
/*out*/ float& carsRate,
/*out*/ float& busesRate,
/*out*/ float& trucksRate)
{


bool invalidData;
invalidData=true;
while(invalidData)
{
cout<<"Enter the tax rate for MOTORCYCLES(0.01-0.99)"< cin>>motorcycleRate;

{

if(0.009<=motorcycleRate&&motorcycleRate<=0.999)
invalidData=false;

else

cout<<"Warning: entry invalid, rate must be between 0.01 and 0.99"<
}
}
invalidData=true;
while(invalidData)
{

cout<<"Enter the tax rate for CARS(0.01-0.99)"< cin>>carsRate;
{
if(0.009<=carsRate&&carsRate<=0.999)
invalidData=false;

else

cout<<"Warning: entry invalid, rate must be between 0.01 and 0.99"<
}
}
invalidData=true;
while(invalidData)
{
cout<<"Enter the tax rate for BUSES(0.01-0.99)"< cin>>busesRate;
{

if(0.009<=busesRate&&busesRate<=0.999)
invalidData=false;

else

cout<<"Warning: entry invalid, rate must be between 0.01 and 0.99"<
}
}
invalidData=true;
while(invalidData)
{

cout<<"Enter the tax rate for TRUCKS(0.01-0.99)"< cin>>trucksRate;
{

if(0.009<=trucksRate&&trucksRate<=0.999)
invalidData=false;

else

cout<<"Warning: entry invalid, rate must be between 0.01 and 0.99"<
}


}

}

2006-07-11 09:07:55 · 4 answers · asked by jdegbor 1 in Computers & Internet Programming & Design

This program is supposed to read from an input file and convert 'm' to MOTORCYCLES, 'c' to CARS, 'b' to BUS and 't' to TRUCKS. an example of an input file would be
b 3500
c 400
5 9000
m 50000
t 4200.5

It is supposed to prompt the user for 4 tax rates(in succession) for the four vehicle types. For e.g the first line from the input file has b for BUS and 3500 as the weight. The program should read the two values, multiply the weight value for bus(in this example) by the approriate tax rate for buses(gathered from user's input) and print out a trable with four columns:
Vehicle type(converted), weight, rate and total tax due(weight * rate).
I am required to use enum data type for MOTORCYCLE, CAR, BUS and TRUCK.

The program is supposed to print error messages to indicate invalid vehicle type or an invalid weight(non-integer) but go on printing and processing the rest of the values.

2006-07-11 09:25:06 · update #1

This is the line that specifies my output(not the heading)
{
if(code=='m')
cout< else if (code=='c')
cout< else if(code=='b')
cout< else if(code=='t')
cout< else
cout< return 0;

2006-07-11 09:29:16 · update #2

this is for when the code is 'm'. All the others follow the same format except for the variables BUS, TRUCK and CAR.
if(code=='m')
cout<

2006-07-11 09:31:09 · update #3

4 answers

Would help if you showed the input, the output and the errors you are experiencing!

2006-07-11 09:13:57 · answer #1 · answered by N2FC 6 · 2 0

try to post code that doesnt have ... after things like setpre, so we can read it easier, try adding some spaces between things if it was yahoo that did that

2006-07-11 09:48:11 · answer #2 · answered by Kristofer 4 · 0 0

double powerTo(double a, int b) { if(b<0) { go back 0; } else { outcome=0; for (b; b>0; b--) { outcome *= a; } } } a million) else grew to grow to be lacking 2) b=a million (no longer mandatory) you attempt to reinitialize b which isn't proper.

2016-10-14 09:00:52 · answer #3 · answered by Erika 4 · 0 0

here/..(I named the project x.cpp)
Compiling...
x.cpp
.\x.cpp(9) : error C2871: 'std' : a namespace with this name does not exist
.\x.cpp(26) : error C2065: 'ifstream' : undeclared identifier
.\x.cpp(26) : error C2146: syntax error : missing ';' before identifier 'inFile'
.\x.cpp(26) : error C2065: 'inFile' : undeclared identifier
.\x.cpp(31) : error C2228: left of '.open' must have class/struct/union
type is ''unknown-type''
.\x.cpp(34) : error C2065: 'cout' : undeclared identifier
.\x.cpp(34) : error C2065: 'endl' : undeclared identifier
.\x.cpp(39) : error C3861: 'setw': identifier not found
.\x.cpp(40) : error C3861: 'setw': identifier not found
.\x.cpp(40) : error C3861: 'setw': identifier not found
.\x.cpp(40) : error C3861: 'setw': identifier not found
.\x.cpp(40) : error C3861: 'setw': identifier not found
.\x.cpp(76) : error C2065: 'fixed' : undeclared identifier
.\x.cpp(76) : error C2065: 'showpoint' : undeclared identifier
.\x.cpp(76) : error C2065: 'setpre' : undeclared identifier
.\x.cpp(76) : error C2143: syntax error : missing ';' before '...'
.\x.cpp(76) : error C2143: syntax error : missing ';' before '...'
.\x.cpp(106) : error C2065: 'cin' : undeclared identifier
.\x.cpp(110) : error C2065: 'moto' : undeclared identifier
.\x.cpp(110) : error C2143: syntax error : missing ')' before '...'
.\x.cpp(110) : error C2143: syntax error : missing ';' before '...'
.\x.cpp(110) : warning C4390: ';' : empty controlled statement found; is this the intent?
.\x.cpp(113) : error C2181: illegal else without matching if
.\x.cpp(126) : error C2059: syntax error : '...'
.\x.cpp(129) : error C2181: illegal else without matching if
.\x.cpp(133) : error C2143: syntax error : missing ')' before '}'
.\x.cpp(133) : error C2143: syntax error : missing ';' before ')'
.\x.cpp(142) : error C2143: syntax error : missing ')' before '...'
.\x.cpp(142) : error C2143: syntax error : missing ';' before '...'
.\x.cpp(142) : warning C4390: ';' : empty controlled statement found; is this the intent?
.\x.cpp(145) : error C2181: illegal else without matching if
.\x.cpp(159) : error C2065: 'trucksRa' : undeclared identifier
.\x.cpp(159) : error C2143: syntax error : missing ')' before '...'
.\x.cpp(159) : error C2143: syntax error : missing ';' before '...'
.\x.cpp(159) : warning C4390: ';' : empty controlled statement found; is this the intent?
.\x.cpp(162) : error C2181: illegal else without matching if
also, did you forget to add "stdafx.h" to yuo headers?

2006-07-11 09:08:59 · answer #4 · answered by V.Vondoom 3 · 0 0

fedest.com, questions and answers