0

Calculate average using pointers and arrays in C++

No void functions. everything in int main. the program should read in 10 numbers

28th Aug 2017, 3:58 AM
hoax
hoax - avatar
1 Réponse
- 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; }
28th Aug 2017, 4:10 AM
hoax
hoax - avatar