Hey Guys!!

I need some help with this.

I want to find a more efficient way to do this. I also want it to have a unlimited amount of numbers that one can average:

Thank-you so much!Code:#include <iostream> #include <stdlib.h> using namespace std; int main(int argc, char * argv[]) { float grade1; float grade2; float grade3; float grade4; float grade5; float grade6; float grade7; float grade8; float grade9; float grade10; int selection; cout<<" Welcome to Average Those Numbers!"<<endl <<"---------------------------------"<<endl <<endl <<"Type in the amount of numbers you would like to average:"<<endl; cin>>selection; if (selection == 1) { cout<<"Type in your numbers:"<<endl; cin>>grade1; float average; average = grade1; cout<<"Your average is "<<average<<endl; return 0; } if (selection == 2) { cout<<"Type in your numbers:"<<endl; cin>>grade1; cin>>grade2; float average; average = (grade1 + grade2) / 2; cout<<"Your average is "<<average<<endl; return 0; } if (selection == 3) { cout<<"Type in your numbers:"<<endl; cin>>grade1; cin>>grade2; cin>>grade3; float average; average = (grade1 + grade2 + grade3) / 3; cout<<"Your average is "<<average<<endl; return 0; } if (selection == 4) { cout<<"Type in your numbers:"<<endl; cin>>grade1; cin>>grade2; cin>>grade3; cin>>grade4; float average; average = (grade1 + grade2 + grade3 + grade4) / 4; cout<<"Your average is "<<average<<endl; return 0; } if (selection == 5) { cout<<"Type in your numbers:"<<endl; cin>>grade1; cin>>grade2; cin>>grade3; cin>>grade4; cin>>grade5; float average; average = (grade1 + grade2 + grade3 + grade4 + grade5) / 5; cout<<"Your average is "<<average<<endl; return 0; } if (selection == 6) { cout<<"Type in your numbers:"<<endl; cin>>grade1; cin>>grade2; cin>>grade3; cin>>grade4; cin>>grade5; cin>>grade6; float average; average = (grade1 + grade2 + grade3 + grade4 + grade5 + grade6) / 6; cout<<"Your average is "<<average<<endl; return 0; } if (selection == 7) { cout<<"Type in your numbers:"<<endl; cin>>grade1; cin>>grade2; cin>>grade3; cin>>grade4; cin>>grade5; cin>>grade6; cin>>grade7; float average; average = (grade1 + grade2 + grade3 + grade4 + grade5 + grade6 + grade7) / 7; cout<<"Your average is "<<average<<endl; return 0; } if (selection == 8) { cout<<"Type in your numbers:"<<endl; cin>>grade1; cin>>grade2; cin>>grade3; cin>>grade4; cin>>grade5; cin>>grade6; cin>>grade7; cin>>grade8; float average; average = (grade1 + grade2 + grade3 + grade4 + grade5 + grade6 + grade7 + grade8) / 8; cout<<"Your average is "<<average<<endl; return 0; } if (selection == 9) { cout<<"Type in your numbers:"<<endl; cin>>grade1; cin>>grade2; cin>>grade3; cin>>grade4; cin>>grade5; cin>>grade6; cin>>grade7; cin>>grade8; cin>>grade9; float average; average = (grade1 + grade2 + grade3 + grade4 + grade5 + grade6 + grade7 + grade8 + grade9) / 9; cout<<"Your average is "<<average<<endl; return 0; } if (selection == 10) { cout<<"Type in your numbers:"<<endl; cin>>grade1; cin>>grade2; cin>>grade3; cin>>grade4; cin>>grade5; cin>>grade6; cin>>grade7; cin>>grade8; cin>>grade9; cin>>grade10; float average; average = (grade1 + grade2 + grade3 + grade4 + grade5 + grade6 + grade7 + grade8 + grade9 + grade10) / 10; cout<<"Your average is "<<average<<endl; return 0; } else { cout<<"Error! Please input only up to 10 grades!"<<endl; system("PAUSE"); } return 0; }

best regards,

Matthew Johnson