+ 1

I can not figure this out. Write a program using an array to prompt for 10 grades and add them all up and divide by 10 to find the average. If a user inputs a negative number, add up all the numbers that are not negative and divide it by the amount of numbers that are not negative. Using two functions other than main.

1st Dec 2016, 1:38 AM
Thomas
Thomas - avatar
4 Antworten
+ 5
#include <iostream.h> int average(array[]){ int sum=0; int j=0; for(int i=0; i<array.size(); i++){ if (array[i]>=0){ sum+=array[i] j++ } } return sum/j } void print(array[]){ // array.size is length of array for(int i=0; i<=array.size(); i++){ cout<<array[i]; } } int main(){ int nos[10 ]; cout<<" Enter the scores "; for( int i=0; i<=10; i++){ cin>>nos[i]; } cout<<" average of the" <<print(nos[])<< " is"<<average[nos]; return 0; }
1st Dec 2016, 3:21 AM
Sandeep Chatterjee
+ 2
Thomas this will reject all negative nos and give average of only positive nos
1st Dec 2016, 3:24 AM
Sandeep Chatterjee
+ 1
Thank you so much
1st Dec 2016, 3:23 AM
Thomas
Thomas - avatar
+ 1
I love you this solves all my problems thank you!
1st Dec 2016, 3:25 AM
Thomas
Thomas - avatar