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

Can someone help me with this question?

Sales Bar Chart

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-03 18:51:56 · 4 answers · asked by Nishimura Aina 1 in Computers & Internet Programming & Design

4 answers

declare array s[];
declare integer ii;
declare integer jj;
declare literal splats := '*******************';

ii := 1;
do while (UserHasInput())
promptUser("Enter today's sales for store "+ii);
s[ii] := userInput();
ii := ii + 1
enddo

print("Sales Bar Chart");
print("Each * = $100");
do for jj := 1 to ii
print("Store "+jj+":"+splats(1:s[jj]/100));
enddo

2007-03-03 19:08:39 · answer #1 · answered by Anonymous · 0 0

There are a couple parts to this. First, finding out how many asterisks to output for a given store, and then actually outputting them.

So, you'll need a loop of some sort that outputs an asterisk every iteration, and run through the number of asterisks you need.

Second, you'll need a loop that does the above for each of the stores entered.

I'm not going to give you code, you should be able to do your own homework. This breaks up into a couple loops pretty easily, just figure out how to break the problem up, write each piece and put them together.

Good luck.

2007-03-03 19:06:38 · answer #2 · answered by Ryan 4 · 0 0

Depends on what program/language?

You can do this with looping.

Basically the number of asterisks you want to print, is the stores total divided by 100.

So if it's 1200, 1200 / 100 = 12. So you want to print 12 asterisks.

You would loop from 1 to 12, printing an asterisk each time.

An example (in PHP):

for ( $i = 1; $i <= 5; $i++ ) // Loop for each store
{
print "Store " . $i . ": ";

for ( $j = 0; $j < $stores[$i] / 100; $j++ )
{
print "*"; // Print an *
}

print "\n"; // Go to a new line
}



You could also do this with a string repeat function if it exists in your language/program of choice.

In Php it would be:

for ( $i = 1; $i <= 5; $i++ ) // Loop for each store
{
print "Store " . $i . ": " . str_repeat("*", $stores[$i] / 100) . "\n";
}

2007-03-03 19:00:25 · answer #3 · answered by Dave W 1 · 0 0

It all depends on what language you are programming in.

here is some suedo code to help get you started-

do until store(1-5)sales < 100
output = "*"
store(1-5)sales = store(1-5)sales - 100
end loop


hope that helped

2007-03-03 19:11:06 · answer #4 · answered by rotanineb 1 · 0 0

fedest.com, questions and answers