Calculating Grades program (Passing grades) (Failing Grades) in C++
Hello everyone. I really need help with this assignment. It's for an online class and I didn't understand the lessons at all. I have been trying to figure out the code for 6 hours but I just don't understand how to solve this problem. Any help will be greatly appreciated by me and my fellow classmates.
This is the assignment. So far we have only learned about repetition using a while loop and logical operators. So please keep that in mind.
We want to count how many passing grades are entered. We don’t know how many grades there will be. Use 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 (meaning either less than zero or greater than 100), present an error message to the user, and do not count that grade as passing. We also would like to see the number of passing grades, the number of failing grades and the number of invalid grades.
Create two more test cases.
Use following one in addition to the two you create.
Grades Entered: Expected Results
45
90
70
87
123 “That is not a valid grade!”
100
-1 You entered 4 passing grades.
You entered one failing grade
You entered one invalid grade.
This is my code so far.
Code:
#include <stdio.h>
#include <stdlib.h>
main()
{
int score, sum=0;
printf("Enter a score (-1 to quit)");
scanf("%i", &score);
while (score != -1) {
}
system("pause");
}
Re: Calculating Grades program (Passing grades) (Failing Grades) in C++
Quote:
Originally Posted by
mikehunter
This is my code so far.
Code:
#include <stdio.h>
#include <stdlib.h>
main() {
int score, sum=0;
printf("Enter a score (-1 to quit)");
scanf("%i", &score);
while (score != -1) {
}
system("pause");
}
And it is what you called "code"???
And where is what you had to implement in this "code" such as:
Quote:
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 (meaning either less than zero or greater than 100), present an error message to the user, and do not count that grade as passing. We also would like to see the number of passing grades, the number of failing grades and the number of invalid grades.
Re: Calculating Grades program (Passing grades) (Failing Grades) in C++
[When posting code, please use code tags for readable code. Go Advanced, select the formatted code and click '#'].
Cheers!
... also your initial loop is not right. You are asking for the score to be entered before the start of the loop - so only one score is ever asked for and input. If this score is -1 then the program terminates straight away. If the entered score is not -1 then the program loops forever! Obtaining the score should be inside a loop.
Re: Calculating Grades program (Passing grades) (Failing Grades) in C++
Quote:
Originally Posted by
mikehunter
It's for an online class and I didn't understand the lessons at all.
To get started there are C++ tutorials on the internet, like here
http://www.ntu.edu.sg/home/ehchua/pr...roduction.html