Answer to Question #260511 in C++ for malika

Question #260511

Array testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full credit is 100, so anything over 100 is extra credit. Ex: If testGrades = {101, 83, 107, 90}, then sumExtra = 8, because 1 + 0 + 7 + 0 is 8.


#include <iostream>

using namespace std;


int main() {

  const int NUM_VALS = 4;

  int testGrades[NUM_VALS];

  int i;

  int sumExtra = -9999; // Assign sumExtra with 0 before your for loop


  for (i = 0; i < NUM_VALS; ++i) {

   cin >> testGrades[i];

  }


  /* Your solution goes here */


  cout << "sumExtra: " << sumExtra << endl;

  return 0;

}


1
Expert's answer
2021-11-04T18:08:01-0400
#include <iostream>


using namespace std;


int main()
{
    const int NUM_VALS = 4;


    int testGrades[NUM_VALS];


    int i;


    int sumExtra = 0; // Assign sumExtra with 0 before your for loop






    for (i = 0; i < NUM_VALS; i++){
        cin >> testGrades[i];
    }
    /* Your solution goes here */
    for (i = 0; i < NUM_VALS; i++){
        if (testGrades[i] >= 100)
            sumExtra += testGrades[i] - 100;
    }




    cout << "sumExtra: " << sumExtra << endl;
    cout << endl << endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS