The question is write a program that reads a file, line byline. The file has 1 c
ID: 3614527 • Letter: T
Question
The question is write a program that reads a file, line byline. The file has 1 character and a price per line, but we DON'Tknow how much data is in the file. The first character is either a'T' (for taxed item) or a 'U' (for untaxed item). Your program mustcompute the subtotal, tax amount, and total. The tax rate is5%. Sampleinput: Sample output file T11.25 Taxable Items Total $20.75 U10.50 Un-taxable Items Total $18.49 U7.99 Subtotal $39.24 T9.50 Tax Amount $1.04 Total $41.20 The way I set up my program is right b/c my professor helpedme, but when i run the program its like 42 errors. Can somebodytake a look @ it and see whats wrong with it. #include<ifstream>#include<iostream> using namespace std;
const double TAXRATE = 0.05;
int main () //declaration section
double taxItemTotal=0,untaxItemTotal=0;
char taxCheck;
double cost;
double subtotal,total, taxAmount;
ifstream inFile;
ofstream outfile;
inFile.open("lab11.txt");
outfile.open("lab11output.txt"); inFile>>taxCheck>>cost; cout<<taxCheck<<" "<<cost<<endl; while (inFile)
{
if(taxCheck == 'T')
taxItemTotal+=cost;
else
untaxItemTotal +=cost;
inFile>>taxCheck>>cost;
}
subtotal = taxItemTotal + untaxItemTotal;
taxAmount= taxItemTotal + TAXRATE;
total= subtotal+ taxAmount;
outfile<<"Taxable Total"<<taxItemTotal<<endl;
outfile<<"Un-taxable Total"<<untaxItemTotal<<endl;
outfile<<"Subtotal"<<subtotal<<endl;
oufile<<"taxAmount"<<taxAmount<<endl;
outfile<<"Total "<<total<<endl;
inFile.close();
outfile.close ();
system("PAUSE");
return 0;
}
The question is write a program that reads a file, line byline. The file has 1 character and a price per line, but we DON'Tknow how much data is in the file. The first character is either a'T' (for taxed item) or a 'U' (for untaxed item). Your program mustcompute the subtotal, tax amount, and total. The tax rate is5%. Sampleinput: Sample output file T11.25 Taxable Items Total $20.75 U10.50 Un-taxable Items Total $18.49 U7.99 Subtotal $39.24 T9.50 Tax Amount $1.04 Total $41.20 The way I set up my program is right b/c my professor helpedme, but when i run the program its like 42 errors. Can somebodytake a look @ it and see whats wrong with it. #include<ifstream>
#include<iostream> using namespace std;
const double TAXRATE = 0.05;
int main () //declaration section
double taxItemTotal=0,untaxItemTotal=0;
char taxCheck;
double cost;
double subtotal,total, taxAmount;
ifstream inFile;
ofstream outfile;
inFile.open("lab11.txt");
outfile.open("lab11output.txt"); inFile>>taxCheck>>cost; cout<<taxCheck<<" "<<cost<<endl; while (inFile)
{
if(taxCheck == 'T')
taxItemTotal+=cost;
else
untaxItemTotal +=cost;
inFile>>taxCheck>>cost;
}
subtotal = taxItemTotal + untaxItemTotal;
taxAmount= taxItemTotal + TAXRATE;
total= subtotal+ taxAmount;
outfile<<"Taxable Total"<<taxItemTotal<<endl;
outfile<<"Un-taxable Total"<<untaxItemTotal<<endl;
outfile<<"Subtotal"<<subtotal<<endl;
oufile<<"taxAmount"<<taxAmount<<endl;
outfile<<"Total "<<total<<endl;
inFile.close();
outfile.close ();
system("PAUSE");
return 0;
}
The question is write a program that reads a file, line byline. The file has 1 character and a price per line, but we DON'Tknow how much data is in the file. The first character is either a'T' (for taxed item) or a 'U' (for untaxed item). Your program mustcompute the subtotal, tax amount, and total. The tax rate is5%. Sampleinput: Sample output file T11.25 Taxable Items Total $20.75 U10.50 Un-taxable Items Total $18.49 U7.99 Subtotal $39.24 T9.50 Tax Amount $1.04 Total $41.20 The way I set up my program is right b/c my professor helpedme, but when i run the program its like 42 errors. Can somebodytake a look @ it and see whats wrong with it. #include<ifstream>
#include<iostream> using namespace std;
const double TAXRATE = 0.05;
int main () //declaration section
double taxItemTotal=0,untaxItemTotal=0;
char taxCheck;
double cost;
double subtotal,total, taxAmount;
ifstream inFile;
ofstream outfile;
inFile.open("lab11.txt");
outfile.open("lab11output.txt"); inFile>>taxCheck>>cost; cout<<taxCheck<<" "<<cost<<endl; while (inFile)
{
if(taxCheck == 'T')
taxItemTotal+=cost;
else
untaxItemTotal +=cost;
inFile>>taxCheck>>cost;
}
subtotal = taxItemTotal + untaxItemTotal;
taxAmount= taxItemTotal + TAXRATE;
total= subtotal+ taxAmount;
outfile<<"Taxable Total"<<taxItemTotal<<endl;
outfile<<"Un-taxable Total"<<untaxItemTotal<<endl;
outfile<<"Subtotal"<<subtotal<<endl;
oufile<<"taxAmount"<<taxAmount<<endl;
outfile<<"Total "<<total<<endl;
inFile.close();
outfile.close ();
system("PAUSE");
return 0;
}
Explanation / Answer
please rate - thanks you had very few errors. I also fixed your output. every lineI changed is in red Note: the total on your same is incorrect #include #include #include using namespace std; const double TAXRATE = 0.05; int main () {//declarationsection double taxItemTotal=0,untaxItemTotal=0; char taxCheck; double cost; double subtotal,total, taxAmount; ifstream inFile; ofstream outfile; inFile.open("lab11.txt"); outfile.open("lab11output.txt"); inFile>>taxCheck>>cost; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.