Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include #include using namespace std; const int NUM=4; int main() { //This is f

ID: 3913062 • Letter: #

Question

#include

#include

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;

}

Explanation / Answer

The c++ code is as follows : I have pointed out wherever you have done mistakes


#include<iostream>
#include<iomanip> // should include this for setprecision
using namespace std;
const int NUM = 5; // should have size 5, for 5 iterations of the for loop
int main()
{
    cout << setprecision(2) << fixed;
    double costArray[NUM];
    double taxArray[NUM] = {0};
    char taxApplied;
    double totalCost = 0.0, totalTax = 0.0;
    for (int i = 0; i < 5; i++) // should have semi colons in between conditions
    {
        cout << "cost?" << endl; // prompting input
        cin >> costArray[i]; // storing cost // should have i instead of 0
        cout << "tax? (y/n)" << endl; // prompting input
        cin >> taxApplied; // taking input
        if (taxApplied == 'y') // should have double =, and single inverted commas for a char
            taxArray[i] = costArray[i] * .10; // storing if yes
    }
    for(int i = 0; i < 5 ; i++)
    {
        cout << taxArray[i] << endl;
    }
    return 0;
}

Output :

cost?
3
tax? (y/n)
y
cost?
4
tax? (y/n)
n
cost?
5
tax? (y/n)
y
cost?
6
tax? (y/n)
n
cost?
7
tax? (y/n)
y
0.30
0.00
0.50
0.00
0.70