111k views
0 votes
Walmart store wants to compare the sales of five of its stores. Write a complete program to ask the user to enter the sales for 5 stores. Create a bar chart displaying stars representing the sale amount for the day. must follow the requirements main method calls the print method. a for loop is required print method accepts an integer as its parameter representing the sale for the day. display stars based on the sale. one star represents $100 sale. a for loop is required Sample output:

User John Dhom
by
4.5k points

1 Answer

2 votes

Answer:

Here is the C++ program.

#include <iostream> //to use input output functions

using namespace std; //to identify objects cin cout

void print(int sales){ //method that accepts integer as its parameter representing the sale for the day

for(int i=0;i<(sales/100);i++){ //loop to create a bar chart

cout<<"*"; } } //prints stars representing the sale amount for the day

int main(){

int sales1; // stores the sales of store 1

int sales2; // stores the sales of store 2

int sales3; // stores the sales of store 3

int sales4; // stores the sales of store 4

int sales5; // stores the sales for store 5

cout<<"Enter the sales for store 1: "; //prompts user to enter sales for store 1

cin >>sales1; //reads the value of sales for store 1 and stores it in sales1

print(sales1); //calls print method to display start representing the sales amount for the day for store 1

cout<<"\\Enter the sales for store 2: "; //prompts user to enter sales for store 2

cin >>sales2; //reads the value of sales for store 2 and stores it in sales2

print(sales2); //calls print method to display start representing the sales amount for the day for store 2

cout<<"\\Enter the sales for store 3: "; //prompts user to enter sales for store 3

cin >>sales3; //reads the value of sales for store 3 and stores it in sales3

print(sales3); //calls print method to display start representing the sales amount for the day for store 3

cout<<"\\Enter the sales for store 4: "; //prompts user to enter sales for store 4

cin >>sales4; //reads the value of sales for store 4 and stores it in sales4

print(sales4); //calls print method to display start representing the sales amount for the day for store 4

cout<<"\\Enter the sales for store 5: "; //prompts user to enter sales for store 5

cin >>sales5; //reads the value of sales for store 5 and stores it in sales5

print(sales5); } //calls print method to display start representing the sales amount for the day for store 5

Step-by-step explanation:

The program is well explained in the comments attached with each line of the program. Lets say user enters 100 as sales for store 1. Then the for loop works as follows:

for(int i=0;i<(sales/100);i++)

At first iteration:

i = 0

i<(sales/100) is true because 0 is less than 100/100 = 1

so the program moves to the body of loop which has the statement:

cout<<"*"

This prints one asterisk one output screen. Next the loop breaks when i = 1. So this only prints one asterisk in output since one star represents $100 sale. The screenshot of the program along with its output is attached.

Walmart store wants to compare the sales of five of its stores. Write a complete program-example-1
User Darren Felton
by
5.3k points