English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

#include
using namespace std;

int main()
{
int sales;
int store;
int asterisks;
int counter;

for (store = 1 ; store <= 5 ; store++)
{
cout << "Enter today's sales for store " << store << ": ";
cin >> sales;
}

cout << endl;
cout << "SALES BAR CHART" << endl;
cout << "(Each * = $100)" << endl;

for (store = 1 ; store <= 5 ; store++)
{
cout << "Store " << store << ": ";

asterisks = sales / 100;
for (counter = 1 ; counter <= asterisks ; counter++)
{
cout << '*';
}
cout << endl;
}
cout << endl;
system ("pause");
return 0;
}


-the program should be, when you type 300, the asterisks will out for 3 times.
-hint: don't use array

2007-03-17 04:03:56 · 6 answers · asked by Nishimura Aina 1 in Computers & Internet Programming & Design

the question:
Write a program that asks 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: *******************

2007-03-17 04:18:03 · update #1

i can't use array of pointers because this question is located under section looping.
so i have to use looping only.
i don't learn array and pointers yet.

2007-03-17 04:19:27 · update #2

6 answers

Looks to me like you ask for the sales for the 5 stores, then you print out the asterisks for the sales of the last store you ask for 5 times. I suspect that's not what you wanted to do. Perhaps the first loop should enclose the asterisk printing and not precede it, and the second loop over the stores should go away altogether.

for (store = 1; store <= 5; store++)
{
// get sales

// calculate # of asterisks

// print store number

for (counter = 1; counter <= asterisks; counter++)
{
// print an asterisk
}

// print an endline
}


.........

ok, I see from your additional information that you want to collect all the sales data before you print out your results. You can do that without storing up the sales in arrays by not printing the results out in the inner loop, but instead accumulate a single string that has the correct number of asterisks and a newline for each store. So each time through the loop you append to the string another set of asterisks and end with a newline. Then when you are out of the loop, you can print out the whole string in one operation. How about that?

Note that you'll still have to nest the loops as I did above, you'll just replace the printing of asterisks with concatenating them into a string, and print out the string outside the loop, after all the data has been collected and the bar chart string composed.

2007-03-17 04:23:03 · answer #1 · answered by Phaedrus 3 · 0 1

Is it your intention for sales not be accumulative across the different stores? Because it overrides the sales number in the previous store.

I don't see how not using array for gathering statistics separately from each store.

2007-03-17 11:21:45 · answer #2 · answered by Andy T 7 · 0 1

if you don't want to use array.. then you can use pointers..(but internally both are same...)

int * sales=new int [5]; // replaces int sales...

and replace every sales by * sales... and you are done..
i hope rest of the code is working fine...

and if you don't want pointers either.. then use five different variables ...


to mr rock...
#include

is the new way of c++..
i guess you never heard of namespaces...
... update your skills.. and come out of past....

2007-03-17 11:14:15 · answer #3 · answered by thekillerkat 3 · 0 1

should say exit (0); not return. also you forgot .h after the name of header file #include is the right way

2007-03-17 11:11:12 · answer #4 · answered by the_rock55_2001 3 · 0 1

Wow, can u teach me some programming?

2007-03-17 11:08:40 · answer #5 · answered by Λir§trikę X³ 3 · 0 2

yor program not wrong

2007-03-17 11:26:07 · answer #6 · answered by Anonymous · 0 0

fedest.com, questions and answers