Hello,

Can anyone help me? I am new to programming. I need to create a program that tracks sales. The store owner wants to keep track of monthly sales.

  1. Ask the user for the monthly income of the store (one question per month) keep the numbers input 0-50. Store all the info in an array.

  2. Calculate the statistics (average, standard deviation, minimum sales and maximum sales for the year.

  3. Output to the screen a text based graph that shows monthly sales for the year.

Sample graph:

*
* *
* * *
* * *
Jan (4) Feb(2) Mar (3)
(the astricks should be above the month in the graph...for some reason it's not showing that way here)

Any help or advice or links to help would be greatly appreciated. :-)

This is probably all wrong but here goes...seems like there are so many different ways to do this. I just need one way that works. :-(

Also, I have no idea how to enter the function for the astricks bar graph. I've been trying for 3 days to figure this out. I've started over like 100 times, researched and studied and am still very much so stuck. This is very frustrating. Any help would be so greatly appreciated.

include <iostream>

include <iomanip>

using namespace std;

void inputData(double[]);
int lowMonth(double[]);
int highMonth(double[]);
double averageSales(double[]);

const char * monthArray[] = {"Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec"};
const int NUM_MONTHS = 12;

int main()
{
double salesArray[NUM_MONTHS];
int low, high;
double average;

inputData(salesArray);


high = highMonth(salesArray);


low = lowMonth(salesArray);


average = averageSales(salesArray);


cout << "The highest sales month was in " << monthArray[high] << " with " << setprecision(2) << fixed << salesArray[high] << endl;
cout << "The lowest sales month was in " << monthArray[low] << " with " << setprecision(2) << fixed << salesArray[low] << endl;
cout << "The average monthly sales for 2011 is  " << setprecision(2) << fixed << average << endl; 

}

void inputData(double sales[])
{
for (int i = 0; i < NUM_MONTHS; i++)
{
cout << "Please enter the sales number from 0-50" << monthArray[i] << " ";
cin >> sales[NUM_MONTHS];
}
return;
}

int highMonth(double sales[])
{
double highest;
highest = sales[i];

for (int i = 0; i < NUM_MONTHS; i++)
{
    if (sales[i] > highest)
    {
        highest = sales[i];
        highest = i;
    }
}
return highest;

}

int lowMonth(double sales[])
{
double lowest;
lowest = sales[0];

for (int i = 0; i < NUM_MONTHS; i++)
{
    if (sales[i] < lowest)
    {
        lowest = sales[i];
        lowest = i;
    }
}
return lowest;

}

double averageSales(double sales[])
{
double sum = 0;

for (int i = 1; i < NUM_MONTHS; i++)
{
    sum += sales[i];
}
return sum / NUM_MONTHS;

}

in inputData NUM_MONTHS is not a valid index for sales[].

in highMonth and lowMonth why assing i to highest and lowest right after you assign sales[i] to it.

There may be other concerns, but that should be a good start.

Aside from it not compiling, these are the errors I'm getting:

error C2065: 'i' : undeclared identifier
warning C4244: 'return' : conversion from 'double' to 'int', possible loss of data

int highMonth(double sales[])
{
double highest;
highest = sales[i];
return highest.

In line 3 above, what you really want is the index of the first element of sales, not i.

The warning is because highest is declared type double, but the return type for the function is type int.

This article has been dead for over six months. Start a new discussion instead.