Bradley L. answered 10/18/22
System Engineer specializing in C/C++
Hi there Mahtab. For loops allow us to iterate through data structures while applying some logic to each element of that data structure.
First thing's first, let's set up our variables and our main method:
I'm using the same values from the example inside our array.
Next, let's make a for loop that iterates through the array:
Now we have our loop prepared. The last thing we need to add is the logic. If the grade is greater than 100, add (grade - 100) to sumExtra:
There we go! The problem is solved. Notice that I included iostream and printed sumExtra to console. This is very important because when you're coding, you should be able to anticipate what the result of running your code is. Being able to compare an expected value to the actual value makes debugging much easier. Hope that helps!