Sales Bar Chart Write a program that asks the user to enter today\'s sales for 5
ID: 3826255 • Letter: S
Question
Sales Bar Chart
Write a program that asks the user to enter today's sales for 5 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 worth of sales. Perform input validation that the sales are non-negative values. Make a loop that forces the user to enter valid information to continue the program.
For example, here is a sample run
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: *******************
using dev C++; no complicated script please just if statements no arrays
Explanation / Answer
Here is your program. The code is bigger because I have to use multiple statements as you said I should not use arrays. I have added comments for your understanding.
#include <iostream>
using namespace std;
int main(){
int store1,store2,store3,store4,store5;
cout<<"Enter today's sales for store 1:";
cin>>store1;
while(store1 < 0) { // loop to force user to enter non negative number
cout<<"Enter valid value:";
cin>>store1;
}
cout<<"Enter today's sales for store 2:";
cin>>store2;
while(store2 < 0) {
cout<<"Enter valid value:";
cin>>store2;
}
cout<<"Enter today's sales for store 3:";
cin>>store3;
while(store3 < 0) {
cout<<"Enter valid value:";
cin>>store3;
}
cout<<"Enter today's sales for store 4:";
cin>>store4;
while(store4 < 0) {
cout<<"Enter valid value:";
cin>>store4;
}
cout<<"Enter today's sales for store 5:";
cin>>store5;
while(store5 < 0) {
cout<<"Enter valid value:";
cin>>store5;
}
cout<<"SALES BAR CHART"<<endl;
cout<<"(Each *= 100)"<<endl;
cout<<"Store 1:";
for(int i=0;i < store1/100;i++){//loop to print asterisk
cout<<"*";
}
cout<<endl;
cout<<"Store 2:";
for(int i=0;i < store2/100;i++){
cout<<"*";
}
cout<<endl;
cout<<"Store 3:";
for(int i=0;i < store3/100;i++){
cout<<"*";
}
cout<<endl;
cout<<"Store 4:";
for(int i=0;i < store4/100;i++){
cout<<"*";
}
cout<<endl;
cout<<"Store 5:";
for(int i=0;i < store5/100;i++){
cout<<"*";
}
cout<<endl;
return 0;
}
Sample Run: -
Enter today's sales for store 1:-2342
Enter valid value:1000
Enter today's sales for store 2:1200
Enter today's sales for store 3:1800
Enter today's sales for store 4:800
Enter today's sales for store 5:1900
SALES BAR CHART
(Each *= 100)
Store 1:**********
Store 2:************
Store 3:******************
Store 4:********
Store 5:*******************
--------------------------------
Process exited after 30.48 seconds with return value 0
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.