don't know why it doesn't add them and call it out The arrays aren't called out, could someone please point out the mistake?The task is to run this code and show all the cost values and the tax values then add them later on
I don't know why it doesn't add them and call it out
The arrays aren't called out, could someone please point out the mistake?The task is to run this code and show all the cost values and the tax values then add them later on
// Purpose: simple - easy - to - use - small-town store calculator
#include <iomanip>
#include <iostream>
using namespace std;
const int NUM = 5;
int main() {
cout << setprecision(2) << fixed;
double costArray[NUM];
double taxArray[NUM] = {0};
char taxAppliedChoice;
double totalCost = 0.0, totalTax = 0.0;
for (int i = 0; i < NUM; i++) {
cout << "cost? ";
cin >> costArray[i];
cout << "tax? (y/n) ";
cin >> taxAppliedChoice;
if (taxAppliedChoice == 'y')
taxArray[i] = costArray[i] * 0.1;
}
cout << endl;
cout << "--------" << endl;
cout << endl;
cout << "For your review, here are your values: " << endl;
cout << endl;
cout << setw(10) << "cost" << setw(10) << "tax" << endl;
cout << endl;
// 5. Loop five times
//add the current element in the cost array to the "totalCost"
//add the current element in the tax array to the "totalTax"
for (int i = 0; i < NUM; i++) {
cout << setw(10) << costArray[i] << setw(10) << taxArray[i] << endl;
}
/*6. Print a line of dashes followed by an endl.
Then print the "totalCost" and "totalTax" nicely in columns */
cout << "-----------" << endl;
cout << setw(10) << totalCost << setw(10) << totalTax << endl;
// 7. Print a message "Your total bill is:" and the total bill amount
cout << "Your total bill is: " << totalCost + totalTax << endl;
}
Step by step
Solved in 2 steps with 1 images