make and run a program that will display the average of scores entered by a user using FUNCTIONS in a Dev C++ application. The program should ask how many times the user will enter scores. sample output: how many scores? 5 85 76 84 90 86 the average score is 84.2
int x ; double result; cout <<"Enter The number : "; cin >> x; result = calc (x); cout << "The result is " << result; //The function : double calc (int num){ int temp , result; for (int i=0; i<num ; i++){ cin>>temp; result +=temp; } return temp/num; }
sorry .... return result/num; :) P:
int temp , result; for (int i=0; i<num ; i++){ cin>>temp; result +=temp; } --is it really a temp? what is temp?
do you mean why did I choose this variable name ? because we need it temporarily , It's a temporary variable helps us to calculate the result I mean when we go out the "for" loop we don't use it .... so it's temporary anyway You could choose the name you like :)
ah ..ok ..i got it :) thanks for the info.
You're welcome at any time :)
Join our real-time social learning platform and learn together with your friends!