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

I don\'t understand how to write the for loop for this program and use the const

ID: 3669336 • Letter: I

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 that I have so far.

Sales Bar Chart

Write a program that asks the user to enter today’s sales for five stores. The program
should then display a bar graph comparing each store’s 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 program’s 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 <iostream>
#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;
}

Explanation / Answer

Answer:

#include <iostream>
#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 i= store1; i > 0; i=i-100)
cout << "*";
  
//Compute the second store's sales

cout << " " << "Store 2:";
for (int j= store2; j > 0; j = j-100)
cout << "*";
  
//Compute the third store's sales
cout << " Store 3:";
for (int k= store3; k > 0;k =k-100)
cout << "*";
  
//Compute the fourth store's sales
  
cout << " " << "Store 4:";
for (int l= store4; l > 0;l=l-100)
cout << "*";
  
//Compute the fifth store's sales
  
cout << " " << "Store 5:";
for (int m= store5 ; m > 0;m=m-100)
cout << "*";
return 0;
}

OutPut:

Store 1:**********
Store 2:********************
Store 3:************
Store 4:******************
Store 5:**************