0
Calculate average using pointers and arrays in C++
No void functions. everything in int main. the program should read in 10 numbers
1 Respuesta
- 1
I have this but not understanding pointers to well.
#include <iostream>
using namespace std;
int main() {
int nums [10];
int counter;
int num=0, min , max ,average, sum =0;
while (counter <10 && num!9999){
cin >> num;
if (num!= 9999){
num [counter] = num;
counter++;}
}
if (counter >10){
max=nums[0];
min=nums[0];
sum=[0];
}
for (int i =1; i < counter; i++){
if ( min>nums [i])
min=nums [i];
if (max < nums [i])
max=nums [i];
sum += nums [i];
}
average = sum/counter;
cout << max;
cout << min;
cout << average;
return 0;
}