I have to make two functions using array. I am stuck. I put the code that I tried.
getSales – prompts the user to enter sales for 5 stores and fills the array.
showBarGraph - displays a bar graph.
Here is an example of the programs output.
Enter today's sales for store 1: 1050 Show 10 *s
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: 1990 Show 19 *s
SALES BAR CHART
( Each * = $ 100)
Store 1: **********
Store 2: ************
Store 3: ******************
Store 4: ********
Store 5: *******************
I am bad at arrays. Can someone tell me whats wrong with the code.
Don't post homework questions
Programmers are good at spotting homework questions; most of us have done them ourselves. Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.
#include <iostream>
#include <iomanip>
usingnamespace std;
constint storesales = 5;
// same names ^^^^^ vvvvvvvvvv ???
void getSales(int i, int storesales[]);
void showBarGraph(int storesales[], double stars);
int main()
{
int i, number; // what is the point of i and number?
// number is unused
double stars;
getSales(i, storesales);
showBarGraph(storesales, stars);
return 0;
}
void getSales(int i, int storesales[])
{
// you need to loop through 5 stores
// this will iterate through i = 0, 1, 2, 3 -> only 4
for (int i = 0; i < 4; i++)
{
cout <<"\nEnter today's sales for store " << i + 1 << ": ";
cin >> storesales[i];
}
}
void showBarGraph(int storesales[], double stars)
{
stars = (storesales []/100); // you didn't specify which element to acess
// within the [], so I don't know how this compiled
for (int i = 0; i < stars; i++)
{
// access each store in the storesales array in here
storesales[i]; // like so (this expression does nothing)
cout <<"\nStore " << i + 1 << ": " ;
cout << "*";
}
} // missing closing brace