dynamic arrays

i understand the general concept, the last 2 labs i did on my own, here's one where I am trying to get it to run

#include <iostream>

#include <iomanip>

using namespace std;

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.

monthSales = new float[total];

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

Cout << (count + 1);

<< ":";

// Fill in code to bring sales into an element of the array

Cin >> monthSales[count];

}

for (count = 0; count < numOfSales; count++)

{

total = total + monthSales[count];

}

average =

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

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

Delete [] monthSales;

Delete [] numOfSales;

monthSales = 0;

numofSales =
Can you please use the code format tags. It's really hard to read what you've posted.

1. float *monthSales; // you must always initialize pointers
2. monthSales = new float[total]; // total is zero, maybe you mean numOfSales

The rest is impenetrable.
Using code tags makes reading and commenting on your code MUCH easier, PLEASE learn to use them:

http://www.cplusplus.com/articles/jEywvCM9/

Hint, you can edit your post and add them.

Your source WITH code tags:

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>

#include <iomanip>

using namespace std;

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.

   monthSales = new float[total];

   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

         Cout << (count + 1);

      << ":";

      // Fill in code to bring sales into an element of the array

      Cin >> monthSales[count];

   }

   for (count = 0; count < numOfSales; count++)

   {

      total = total + monthSales[count];

   }

   average =

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

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

   Delete[] monthSales;

   Delete[] numOfSales;

   monthSales = 0;

   numofSales =


There are problems with your code.

1. no need to double space each line, it makes your code harder to read and understand.

2. C++ is case sensitive, cin and Cin are not the same. Same for cout and Cout, delete and Delete.

3. you are missing a number of semicolons, so separate code lines the compiler sees as part of the same code.

4. You are missing at least one closing bracket }.

5. there are several times you start to assign a value to a variable, without any value. Or a semicolon to finish the code statement.

Visual Studio 2019 found 12 syntax errors, even before trying to compile, there are more than that hidden by the documented errors.

Your code is, let's be honest, a mess.
Topic archived. No new replies allowed.