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.
#include <cstdlib>
#include <iostream>
usingnamespace std;
//Prototypes
void getData(int, int *);
int main(int argc, char *argv[])
{
int days;
int *calorie;
int sum = 0;
int average = 0;
calorie = newint[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];
}
}