I am wondering why does this program crash:
Code:
#include <stdlib.h>
#include <iostream>
using namespace std;
int main(int argc,char **argv)
{
int *num=NULL; //Array for storing numbers..
int i=0; //Counter
cout<<"--Program for finding number average--\n"<<
"------------Input 0 to stop-----------\n\n";
while(1)
{
int n; //Dummy variable
cout<<"Enter number "<<i+1<<": ";
cin>>n;
if(n==0) break;
num=new int; //Allocate space for number
num[i]=n;
++i;
}
int aver=0;
for(int x=0;x<i;++x) aver+=num[x];
cout<<"Average of inputed numbers is: "<<aver/i;
cin.get();
for(int x=0;x<i;++x) delete num;
return 1;
}