I'm completely new to programming, as I am taking COP 1000. I only know what's been taught. This is the assignment that's being asked of me:
In this part you will write a C program to solve a problem described in English.
Create a sentinel controlled while loop that will ask the user to enter student grades until a value of -1 is entered. Use a counter variable to count all the grades that are passing grades, where 70 is the minimum passing grade. If there are any grades that are out of the range 0 – 100, present an error message to the user, and do not count that grade as passing.
Create 4 test cases. Use this as one of them:
Grades Entered: Expected Results
45
90
70
87
123 “That is not a valid grade!”
100
-1 You entered 4 passing grades.
I can not for the life of me figure this out. Where I'm getting stuck is trying to get the program to calculate the total passing grades at the end.
This is what I've got so far. It's very amateurish I'm sure. The reason why I was trying to convert the grade to "1" is because I was trying to make that accumulate to create a number of total passing grades. I've been on this for hours and I've realized that that method probably won't work. However, I don't know what to do. This is due tomorrow and I can't figure out how to do this.
The code is below:
Code:
#include <stdio.h>;
#include <stdlib.h>
main() {
int grade, totalPassing = 1;
printf("Enter test grade (-1 to quit):");
scanf_s("%i", &grade);
while (grade != -1)
{
printf("Enter test grade (-1 to quit):");
scanf_s("%i", &grade);
{
if (grade > 100 || grade < 70)
printf("That is not a valid grade! \n");
}
if (grade <= 100 && grade >= 70)
grade = 1;
else
grade = 0;
}
totalPassing = grade + 1;
printf("You've entered %i passing grades! \n");
system("pause");
}