Help with a few lines of code

Hi, i'm just trying to finish up this code and need some help with the parts commented out that say fill in. Thanks

int main()
{
float *monthSales; // a pointer used to point to an array
// holding monthly sales
float total = 0; // total of all sales
float average; // average of monthly sales
int numOfSales; // number of sales to be processed
int count; // loop counter

cout << fixed << showpoint << setprecision(2);
cout << "How many monthly sales will be processed? ";
cin >> numOfSales;
// Fill in the code to allocate memory for the array pointed to by
// monthSales.
if ( // Fill in the condition to determine if memory has been
// allocated (or eliminate this if construct if your instructor
// tells you it is not needed for your compiler)

)

{

cout << "Error allocating memory!\n";
return 1;

}

cout << "Enter the sales below\n";
for (count = 0; count < numOfSales; count++)
{
cout << "Sales for Month number "
<< // Fill in code to show the number of the month
<< ":";
// Fill in code to bring sales into an element of the array
}
for (count = 0; count < numOfSales; count++)
{
total = total + monthSales[count];
}

average = // Fill in code to find the average
cout << "Average Monthly sale is $" << average << endl;
// Fill in the code to deallocate memory assigned to the array.
return 0;
closed account (48T7M4Gy)
Was the homework to fill in the other bits?
Hello Demii,

Look at the comments I put in the code. If you work on one step at a time It is not that hard.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
int main()
{
	float *monthSales; // a pointer used to point to an array
					   // holding monthly sales
	float total = 0; // total of all sales
	float average; // average of monthly sales
	int numOfSales; // number of sales to be processed
	int count; // loop counter

	cout << fixed << showpoint << setprecision(2);
	cout << "How many monthly sales will be processed? ";
	cin >> numOfSales;

	// Fill in the code to allocate memory for the array pointed to by
	// monthSales.

	//Step 1.
	monthSales = // Fill in missing code.


	//Step 2.

	if ( /* Fill in the condition to determine if memory has been
		// allocated (or eliminate this if construct if your instructor
		// tells you it is not needed for your compiler)*/)

	//Step 3.
	// Two Things missing here.

	{

		cout << "Error allocating memory!\n";
		return 1;

	}

	cout << "Enter the sales below\n";
	for (count = 0; count < numOfSales; count++)
	{
		cout << "Sales for Month number "
		//Step 4.
		<< // Fill in code to show the number of the month
			<< ":";

		//Step 5.
		// Fill in code to bring sales into an element of the array
	}
	for (count = 0; count < numOfSales; count++)
	{
		total = total + monthSales[count];
	}

	//Step 6.
	average = // Fill in code to find the average

		cout << "Average Monthly sale is $" << average << endl;

	//Step 7.
	// Fill in the code to deallocate memory assigned to the array.


	return 0;
}


Which step do you not understand?

Hope that helps,

Andy
Hello Demii,

My bad, disregard step 3. When I started working with the code I realized how it is working and now see that nothing is missing except the if condition.

Andy
closed account (48T7M4Gy)
I'd say OP has bolted because of the misunderstanding that this is a homework site :)
@kemort

Very possible. If that is true it is to bad he/she missed out on all the time I would have spent helping.

Now that I am finished with the program it was fun to work on.

Andy
closed account (48T7M4Gy)
Yeah, it's of course up to you but there are plenty of others who need your valuable help :)
@kemort,

Thank you. Nice to be appreciated.

Andy
Topic archived. No new replies allowed.