#include <iostream> #include <iomanip> using namespace std; const int NUM=4; int
ID: 3913063 • Letter: #
Question
#include <iostream>
#include <iomanip>
using namespace std;
const int NUM=4;
int main()
{
//This is for printing money in the proper format
cout << setprecision(2) << fixed;
//1. Declare two arrays one for cost and one for tax
double costArray[NUM];
double taxArray[NUM]={0};
//2. Declare additional variables such as letter input, totals for cost and tax.
char taxApplied;
double totalCost=0.0, totalTax=0.0;
//3. Loop five times
for (int i=0, i<5, i++)
{
//i. prompt for cost
cout << "cost? ";
//ii. input the cost into the array
cin >> costArray[0];
//iii. prompt for y and n
cout << "tax? (y/n) ";
//iv. input the y and n
cin >> taxApplied >> endl;
//v. if the letter is y, then store the tax into the tax array
if (taxApplied = "y")
taxArray[i]=costArray[i]*.10;
}
return 0;
}
Find the errors in 1 2 and 3. and fix them
Explanation / Answer
Fixed code
..... error is written on comments on the line in which error occured ....
#include <iostream>
#include <iomanip>
using namespace std;
const int NUM=4;
int main()
{
//This is for printing money in the proper format
cout << setprecision(2) << fixed;
//1. Declare two arrays one for cost and one for tax
double costArray[NUM];
// double taxArray[NUM]={0}; // error
double taxArray[NUM];
//2. Declare additional variables such as letter input, totals for cost and tax.
char taxApplied;
double totalCost=0.0, totalTax=0.0;
//3. Loop five times
for (int i=0; i<5; i++) // error fixed replaced comma (,) with semicolon (;)
{
//i. prompt for cost
cout << "cost? ";
//ii. input the cost into the array
cin >> costArray[i];
//iii. prompt for y and n
cout << "tax? (y/n) ";
//iv. input the y and n
cin >> taxApplied; // >> endl; //error fixed, removed endl
//v. if the letter is y, then store the tax into the tax array
if (taxApplied == 'y') //error fixed
taxArray[i]=costArray[i]*.10;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.