repl.it
@sdemodica/

Ch 7 Programming Challenge #12

C++

No description

fork
loading
Files
  • main.cpp
main.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main()
{
  const int studNames = 5,
            letterGrade = 5,
            testScores = 4;

  string names[studNames];

  char grades[letterGrade];

  double stud1[testScores];
  double stud2[testScores];
  double stud3[testScores];
  double stud4[testScores];
  double stud5[testScores];

  double average1,
         average2,
         average3,
         average4,
         average5,
         total1 = 0,
         total2 = 0,
         total3 = 0,
         total4 = 0,
         total5 = 0;


for(int count = 0; count < studNames; count++)
{
  cout << "\nEnter student name " << (count + 1) << endl;

  getline(cin, names[count]);
}


for(int count = 0; count < testScores; count++)
{
  cout << "\n----------------------------------------------------";

  cout << "\nEnter test score number " << (count + 1) << " for " << names[0] << endl;

  cin >> stud1[count];

  if(stud1[count] < 0 || stud1[count] > 100)
  {
    cout << "\n~~~~Enter a test score of 0 or greater and 100 or less!";

    exit(0);
  }

  cout << "\nEnter test score number " << (count + 1) << " for " << names[1] << endl;

  cin >> stud2[count];

  if(stud2[count] < 0 || stud2[count] > 100)
  {
    cout << "\n~~~~Enter a test score of 0 or greater and 100 or less!";

    exit(0);
  }

  cout << "\nEnter test score number " << (count + 1) << " for " << names[2] << endl;

  cin >> stud3[count];

  if(stud3[count] < 0 || stud3[count] > 100)
  {
    cout << "\n~~~~Enter a test score of 0 or greater and 100 or less!";

    exit(0);
  }

  cout << "\nEnter test score number " << (count + 1) << " for " << names[3] << endl;

  cin >> stud4[count];

  if(stud4[count] < 0 || stud4[count] > 100)
  {
    cout << "\n~~~~Enter a test score of 0 or greater and 100 or less!";

    exit(0);
  }

  cout << "\nEnter test score number " << (count + 1) << " for " << names[4] << endl;

  cin >> stud5[count];

  if(stud5[count] < 0 || stud5[count] > 100)
  {
    cout << "\n~~~~Enter a test score of 0 or greater and 100 or less!";

    exit(0);
  }

  cout << "----------------------------------------------------\n";
}


for(int count = 0; count < testScores; count++)
{
  total1 += stud1[count];
  average1 = total1/testScores;

  total2 += stud2[count];
  average2 = total2/testScores;

  total3 += stud3[count];
  average3 = total3/testScores;

  total4 += stud4[count];
  average4 = total4/testScores;

  total5 += stud5[count];
  average5 = total5/testScores;
}

{
if(average1 >= 90 && average1 <= 100)
{
  grades[0] = 'A';
}
else if(average1 < 90 && average1 >= 80)
{
  grades[0] = 'B';
}
else if(average1 < 80 && average1 >= 70)
{
  grades[0] = 'C';
}
else if(average1 < 70 && average1 >= 60)
{
  grades[0] = 'D';
}
else if(average1 < 60 && average1 >= 0)
{
  grades[0] = 'F';
}
}


{
if(average2 >= 90 && average2 <= 100)
{
  grades[1] = 'A';
}
else if(average2 < 90 && average2 >= 80)
{
  grades[1] = 'B';
}
else if(average2 < 80 && average2 >= 70)
{
  grades[1] = 'C';
}
else if(average2 < 70 && average2 >= 60)
{
  grades[1] = 'D';
}
else if(average2 < 60 && average2 >= 0)
{
  grades[1] = 'F';
}
}


{
if(average3 >= 90 && average3 <= 100)
{
  grades[2] = 'A';
}
else if(average3 < 90 && average3 >= 80)
{
  grades[2] = 'B';
}
else if(average3 < 80 && average3 >= 70)
{
  grades[2] = 'C';
}
else if(average3 < 70 && average3 >= 60)
{
  grades[2] = 'D';
}
else if(average3 < 60 && average3 >= 0)
{
  grades[2] = 'F';
}
}


{
if(average4 >= 90 && average4 <= 100)
{
  grades[3] = 'A';
}
else if(average4 < 90 && average4 >= 80)
{
  grades[3] = 'B';
}
else if(average4 < 80 && average4 >= 70)
{
  grades[3] = 'C';
}
else if(average4 < 70 && average4 >= 60)
{
  grades[3] = 'D';
}
else if(average4 < 60 && average4 >= 0)
{
  grades[3] = 'F';
}
}


{
if(average5 >= 90 && average5 <= 100)
{
  grades[4] = 'A';
}
else if(average5 < 90 && average5 >= 80)
{
  grades[4] = 'B';
}
else if(average5 < 80 && average5 >= 70)
{
  grades[4] = 'C';
}
else if(average5 < 70 && average5 >= 60)
{
  grades[4] = 'D';
}
else if(average5 < 60 && average5 >= 0)
{
  grades[4] = 'F';
}
}


cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";

cout << "\nThe average test score for " << names[0] << " is: " << average1 << endl;
cout << "And the letter grade is: " << grades[0] << endl;

cout << "\nThe average test score for " << names[1] << " is: " << average2 << endl;
cout << "And the letter grade is: " << grades[1] << endl;

cout << "\nThe average test score for " << names[2] << " is: " << average3 << endl;
cout << "And the letter grade is: " << grades[2] << endl;

cout << "\nThe average test score for " << names[3] << " is: " << average4 << endl;
cout << "And the letter grade is: " << grades[3] << endl;

cout << "\nThe average test score for " << names[4] << " is: " << average5 << endl;
cout << "And the letter grade is: " << grades[4] << endl;

cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";


return 0;
}
Fetching token
?