+ 4
Simulate C ++ running tracker for athletes
The program stores 5 inputs into an array . I need to display the average evertime i take input and store in array before the next input . My code https://code.sololearn.com/cl9QrpAL9CvI/?ref=app Any help would be appreciated.
1 Respuesta
+ 6
Due to how Code Playground works with inputs, you might face issues running the code here when you put cin statements in loops. Just letting you know in advance.
From the looks of it, you don't really need variable j and the whole if statement to do the job.
#include <iostream>
using namespace std;
int main() {
int hundredM[5];
for (int i=0;i<5;i++){
cout << "enter race time " << i+1 << "\n";
cin >> hundredM [i];
int average =0;
for (int x=0;x<i+1;x++)
average += hundredM[x];
cout << "average is :" << average/(i+1) << "\n";
}
return 0;
}
Do you want the computed average values to be stored in another array as well?