Adding arrays without messing with the main program?

I did the program but my teacher says i need to make a array in this program without messing with "int main" part expect for changing few variables in there, most of the work has to be done in "void input". we strated arrays a few days ago but its not clicking for me. The function for this program is to give the average grade from 3 grades and also shows the letter grade but with arrays i need for it to ask me for 10 grades "const int N=10;"

My working normal program(no array)

so can anyone please help me combine these simple programs

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
#include <iostream>
using namespace std;

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 &t1, int &t2, int &t3){
    cout<<"Enter test1"<<endl;
    cin>>t1;
    cout<<"Enter test2"<<endl;
    cin>>t2;
    cout<<"Enter test3"<<endl;
    cin>>t3;
}

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;
}



works alright, best array i could do:

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
// Input (): get 10 grades from user into array
//Calculate (): find and return average of grades
//lettergrade():find and return lettergrade of average
//output(): display average and letter grade
//int main (){
//  int grades[N]
//  double averag;
//  char letter;

#include <iostream>
using namespace std;

int main()
{
// Declare Variables
const int TOTAL_NUMBERS = 10;
int numbers[TOTAL_NUMBERS];
double average;
double sum = 0.0;
int num;

//Read all numbers
for (int i = 0; i < TOTAL_NUMBERS; i++)
{
cout << "Enter a score: ";
cin >> num;
numbers[i] = num;
sum += numbers[i];
}

//Find the average
average = sum/10;

// Display average
cout <<"\nThe average score is " << average <<"\n\n";


return 0;
}



Last edited on
bump.
Topic archived. No new replies allowed.