QUESTION IMAGE
Question
array testgrades contains num_vals test grades read from input. organize the lines of code to create a for loop that sets sumextra to the total extra credit received. full credit is 100, so any grade over 100 has extra credit.
ex: if the input is 101 83 107 90, then the output is sumextra: 8, because 1+0+7+0 is 8.
note: not all lines of code on the left should be used in the final solution.
how to use this tool
unused
for (i = 0; i <= num_vals; ++i) {
for (i = 0; i < num_vals; ++i) {
if (testgradesi < 100) {
if (testgradesi > 100) {
}
}
sumextra = 0;
sumextra = sumextra + (testgradesi - 100);
main.cpp
#include <iostream>
using namespace std;
int main() {
const int num_vals = 4;
int testgradesnum_vals;
int i;
int sumextra;
for (i = 0; i < num_vals; ++i) {
cin >> testgradesi;
}
cout << \sumextra: \ << sumextra << endl;
return 0;
}
Step1: Initialize sumExtra to 0
sumExtra = 0;
Step2: Loop through all test grades
for (i = 0; i < NUM_VALS; ++i) {
Step3: Check if grade exceeds 100
if (testGrades[i] > 100) {
Step4: Add excess to sumExtra
sumExtra = sumExtra + (testGrades[i] - 100);
Step5: Close conditional and loop
}
}
Step6: Output the final sumExtra
cout << "sumExtra: " << sumExtra << endl;Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
The completed code snippet for main.cpp is:
#include <iostream>
using namespace std;
int main() {
const int NUM_VALS = 4;
int testGrades[NUM_VALS];
int i;
int sumExtra;
sumExtra = 0;
for (i = 0; i < NUM_VALS; ++i) {
cin >> testGrades[i];
}
for (i = 0; i < NUM_VALS; ++i) {
if (testGrades[i] > 100) {
sumExtra = sumExtra + (testGrades[i] - 100);
}
}
cout << "sumExtra: " << sumExtra << endl;
return 0;
}
For input 101 83 107 90, the output will be sumExtra: 8.