# Write a program that asks the user to enter today’s sales for five stores. The program should then display a bar chart comparing each store’s sales. Create each bar in the bar chart by displaying a row or asterisks. Each asterisk should represent \$100 of sales. You must use a loop to print the bar chart. If the user enters a negative value for the sales amount, the program will keep asking the user to enter the sales amount until a positive amount is entered, You must use methods, loops and arrays for this assignment. Sample Run 1: Enter today's sale for store 1 (negative value not allowed) 1000 Enter today's sale for store 2 (negative value not allowed) 1200 Enter today's sale for store 3 (negative value not allowed) 1800 Enter today's sale for store 4 (negative value not allowed) 800 Enter today's sale for store 5 (negative value not allowed) 1900 SALES BAR CHART Store 1:********** Store 2:************ Store 3:****************** Store 4:******** Store 5:*******************

Question
13 views

Write a program that asks the user to enter today’s sales for five stores. The program should then display a bar chart comparing each store’s sales. Create each bar in the bar chart by displaying a row or asterisks. Each asterisk should represent \$100 of sales. You must use a loop to print the bar chart. If the user enters a negative value for the sales amount, the program will keep asking the user to enter the sales amount until a positive amount is entered, You must use methods, loops and arrays for this assignment. Sample Run 1: Enter today's sale for store 1 (negative value not allowed) 1000 Enter today's sale for store 2 (negative value not allowed) 1200 Enter today's sale for store 3 (negative value not allowed) 1800 Enter today's sale for store 4 (negative value not allowed) 800 Enter today's sale for store 5 (negative value not allowed) 1900 SALES BAR CHART Store 1:********** Store 2:************ Store 3:****************** Store 4:******** Store 5:*******************

check_circle

Step 1

Following is the c++ program that takes as input from user sales of five stores and display the sales as a bar chart:

Approach:

• Define method display to display the sales of five stores represented by asterisk where each asterisk is equal to \$100 of sales.
• Defining the main method.
• Declaring the variables as per the requirement.
• Using a do-while loop to validate the sales entered by the user must be greater than \$0.00.
• Prompt the user to enter the sales of five stores.
• Call display method.

Step 2

Code:

#include <iostream>

using namespace std;

void display(int sales[5]) {

//display message

cout << "\n    DAILY SALES OF STORES\n    (each * = \$100)\n";

//outer for loop to itterate over the five stores

for (int i = 0; i < 5; ++i) {

cout << "\nStore" << i + 1<<": ";

//inner for loop to display sales of store using asterisk

for (int j = 0; j < sales[i]; ++j) {

cout << "* ";

}

}

}

int main() {

int Sales[5];

//for loop to itterate over the elements of array to save the sales of five stores

for (int i = 0; i < 5; i++) {

// using do while loop to validate sales of Store1

do {

//prompt user to enter sal...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in