How do I "resize" an array?
Maybe this is stupid, but this is the code:
Code:
#include<iostream.h>
#include<stdio.h>
//#include"..\libs\myutil.h"
int main(){
int ofnum; //<---declaration
cout << "How many number to enter: ";
cin >> ofnum;
double numbers[ofnum]; //<----------------------------problem
for(int x=0;x <=ofnum-1; x++){
cout << "Enter number #" << (x+1) << ": "; // <---ask for number 5 times
cin >> numbers[x];
}
double total = numbers[0];
for(int x=1;x<=ofnum-1;x++){ // <---- add all together
total +=numbers[x];
}
total/=ofnum; //<---get average
cout << "Average is: " << total << endl; // <----display result
getchar();
return 0;
}
it says it can only accept constants. My teacher won't help me.