I need help with pointers

I keep getting a runtime error :( can anyone help me with pointer variables? im tring to seperate my main into functions and pass the information usuing pointers.

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
  #include <cstdlib>
#include <iostream>

using namespace std;

//Prototypes
void getData(int, int *);

int main(int argc, char *argv[])
{
    int days;
    int *calorie;
    
    int sum = 0;
    int average = 0;
    
    calorie = new int[days];
    getData(days,calorie);
    
     for (int i = 0; i < days; i++)
         {
              sum+=calorie[i];
         }
     average = (float)sum / (float)days;
    
    cout << days << endl;
    cout << sum << endl;
    cout << showpoint << average << endl;
    for (int i = 0; i < days; i++)
        {
        cout << calorie[i] << endl;
        }
        
    system("PAUSE");
    return EXIT_SUCCESS;
}

        
void getData(int days, int *calorie)
{
     cout << "Please type how many days to track for the month 1-31" << endl;
    cin >> days;
    while (days <= 0 || days > 31)
          {
                cout << "please provide a valide amount" << endl;
                cin >> days;
                }
          
    for (int i = 0; i < days; i++)
        {
          cout << " How many calories where taken? " << endl;
          cin >> calorie[i];   
        }    
}
    

Topic archived. No new replies allowed.