Help with basic arrays
Oct 17, 2012 at 12:08am UTC
We just stared with arrays today and i have a hard time understanding them. I am trying to implement arrays into a program i already did before, the program finds the average of 3 grades and gives a letter grade too. I need to implement the arrays to find 10 grades and a letter grade too.
Here is my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
using namespace std;
const int N=10;
double math(int test1, int test2, int test3){
return double (test1+test2+test3)/3.0;
}
void output (double avg1, char lg){
cout<<"Your average is: " << avg1;
cout<<" You made a: " << lg;
}
void input(int division, int ){
{
int array[N]; //Declaring array
int sum=0;
for (int i=0;i<N;i++) //Loop which inputs arrays data and
//Calculates its sum
{
cout<<"Enter test " <<i+1<<endl;
cin>>array[i];
sum=sum+array[i];
}
//Now calling division function to find the sum...
cout<<"Average of array elements is " <<division(sum,N);
return double (average)/3.0; (int sum,int N);
}
}
char lettergrade (double average)
{
if (average>=93){
return 'A' ;
}
else if ((85<= average)&&(average <=93)){
return 'B' ;
}
else if ((76<= average)&&(average <=85)){
return 'C' ;
}
else if ((70<= average)&&(average <=76)){
return 'D' ;
}
else if ((0<= average)&&(average <=70)){
return 'F' ;
}
}
int main()
{
int grade1;
int grade2;
int grade3;
double average;
char let;
cout<<"Enter grade 1:" <<endl;
cin>>grade1;
cout<<"Enter grade 2:" <<endl;
cin>>grade2;
cout<<"Enter grade 3:" <<endl;
cin>>grade3;
average = math(grade1, grade2, grade3);
let = lettergrade(average);
output (average, let);
return 0;
}
Topic archived. No new replies allowed.