Hi, I have to write a program accepts a varying number of prices (determined by the user) and runs a few calculations based on those prices. I am required to use a controlled for-loop. This is how far I was able to get. I have no idea what variable holds the sum of all the prices or how I would go about displaying it. Can someone lend me a hand? Note that I left the calculation function blank because I don't know where the value is stored. As is, the program compiles and accepts the right prices, but nothing more.
# include <iostream>
# include <iomanip>
usingnamespace std;
// Function prototypes
void getNumber(double);
double prices();
double calculate();
void displayResult();
// Main function executes all other functions
int main()
{
double sold;
double prices;
double sum;
double calculate();
cout << "==========================================================" << endl;
getNumber(sold);
// prices();
calculate();
void disaplayResult();
}
// Ask user for number of items in the order and price of each item
void getNumber(double)
{
double num, value, sum=0;
int counter;
cout << "How many items were purchased? ";
cin >> num;
for (counter=1; counter <= num; counter++)
{
cout << "Enter an item price: ";
cin >> value;
sum +=value;
}
}
// Calculate subtotal, tax, and order total
double calculate()
{
}
// Display the final order information
void displayResult(double& sum)
{
cout << setprecision(2) << fixed;
cout << left; // Align text to the left side
cout << setw(19) << "Subtotal: " << endl;
cout << setw(19) << "Sales Tax: " << endl;
cout << setw(19) << "Total: " << endl;
}
# include <iostream>
# include <iomanip>
usingnamespace std;
// Function prototypes
void getNumber(double);
double prices();
double calculate();
void displayResult();
// Main function executes all other functions
int main()
{
double sold;
double prices;
double sum;
double calculate();
cout << "==========================================================" << endl;
getNumber(sold);
// prices();
calculate();
void disaplayResult();
}
// Ask user for number of items in the order and price of each item
void getNumber(double)
{
double num, value, sum=0;
int counter;
cout << "How many items were purchased? ";
cin >> num;
for (counter=1; counter <= num; counter++)
{
cout << "Enter an item price: ";
cin >> value;
sum +=value;
}
cout<<"Sum of: "<<sum;
}
// Calculate subtotal, tax, and order total
double calculate()
{
}
// Display the final order information
void displayResult(double& sum)
{
cout << setprecision(2) << fixed;
cout << left; // Align text to the left side
cout << setw(19) << "Subtotal: " << endl;
cout << setw(19) << "Sales Tax: " << endl;
cout << setw(19) << "Total: " << endl;
}
@quantumleap-
line 16: You don't initialize sum.
line 26: You need to give the argument a name. In this case it should be sum and you need to pass it by reference.
Line 28: Remove sum as a local variable.