Question: I don't understand how to write the for loop for this program and use the constant char variable. Below is the question and my code

I don't understand how to write the for loop for this program and use the constant char variable. Below is the question and my code that I have so far.

Sales Bar Chart

Write a program that asks the user to enter todays sales for five stores. The program should then display a bar graph comparing each stores sales. Create each bar in the bar graph by displaying a row of asterisks. Each asterisk should represent $100 of sales. Here is an example of the programs output. Enter today's sales for store 1: 1000 [Enter] Enter today's sales for store 2: 1200 [Enter] Enter today's sales for store 3: 1800 [Enter] Enter today's sales for store 4: 800 [Enter] Enter today's sales for store 5: 1900 [Enter] SALES BAR CHART (Each * = $100) Store 1: ********** Store 2: ************ Store 3: ****************** Store 4: ******** Store 5: *******************

Constraints:

Do not develop this program using separate functions - develop it as a single main function. Input Validation: The sales for each store must be greater than zero. If a value less than zero is entered the user must be prompted to enter a valid value. The program MUST use for loops to display the bar charts. Use symbolic constant for the bar chart asterick, '*'. Output should look like the Sample Softcopy in your book, i.e. there is an example of the screen output in your book.

Code:

#include #define const char "*"; using namespace std;

int main() { int store1, store2, store3, store4, store5;

//Ask for the sales for Store 1 cout << "Enter today's sales for Store 1:"; cin >> store1; //Ask for the sales for Store 2 cout << "Enter today's sales for Store 2:"; cin >> store2; //Ask for the sales for Store 3 cout << "Enter today's sales for Store 3:"; cin >> store3; //Ask for the sales for Store 4 cout << "Enter today's sales for Store 4:"; cin >> store4; //Ask for the sales for Store 5 cout << "Enter today's sales for Store 5:"; cin >> store5;

//Display Sales Bar Chart cout << " SALES BAR CHART "; cout << "(Each * = $100 ";

//Compute the first store's sales store1 = store1 / 100; cout << "Store 1:"; for (int store1 = 0; store1 > 0;) cout << store1 << "*"; //Compute the second store's sales store2 = store2 / 100; cout << "Store 2:"; for (int store2 = 0; store2 > 0;) cout << store2 << "*"; //Compute the third store's sales store3 = store3 / 100; cout << "Store 3:"; for (int store3 = 0; store3 > 0;) cout << store3 << "*"; //Compute the fourth store's sales store4 = store4 / 100; cout << "Store 4:"; for (int store4 = 0; store4 > 0;) cout << store2 << "*"; //Compute the fifth store's sales store5 = store5 / 100; cout << "Store 5:"; for (int store5 = 0; store5 > 0;) cout << store5 << "*"; return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!