Using do while

So I need help figuring out why my output isn't correct. I got the number of students to output correctly. I need to figure out why the correct grade isn't showing?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
using namespace std;

int main()
{
	int numberOfStudents;
	int test1;
	int test2;
	int test3;
	int test4;
	int finalGrade;
	int i = 0;
	
	//Enter number of students to find their grade based off of 4 tests
	cout << "Enter the number of students: ";
	cin >> numberOfStudents;
	
	do //begin loop
	{
		
		//Each test is out of 100
		cout << "Student " << i + 1 << " test 1 grade is: ";
		cin >> test1;
		cout << "Student " << i + 1 << " test 2 grade is: ";
		cin >> test2;
		cout << "Student " << i + 1 << " test 3 grade is: ";
		cin >> test3;
		cout << "Student " << i + 1 << " test 4 grade is: ";
		cin >> test4;

		
		finalGrade = (test1 + test2 + test3 + test4) / 400;
		

		//finding each grade 
		if (finalGrade >= 372 && finalGrade <= 400)
		{
			cout << "Student " << i + 1 << " grade is A." << endl;
		}
		else if (finalGrade >= 340 && finalGrade <= 371)
		{
			cout << "Student " << i + 1 << " grade is B." << endl;
		}
		else if (finalGrade >= 280 && finalGrade <= 339)
		{
			cout << "Student " << i + 1 << " grade is C." << endl;
		}
		else if (finalGrade >= 240 && finalGrade <= 279)
		{
			cout << "Student " << i + 1 << " grade is D." << endl;
		}
		else if (finalGrade < 240)
		{
			cout << "Student " << i + 1 << " grade is F." << endl;
		}
		else
		{
			cout << "Total can not be more than 400 points." << endl;
			break;
		}
		i++;
		
	} 
	while (numberOfStudents > i);
}
Last edited on
while ();

While what?
What is each test out of?
Okay, I got the output right except for the grade. @Repeater.
Each test is out of 100 which I do have to figure out how to do that @lastchance.
Last edited on
If each test is out of 100 (0 - 100), and you have 4 tests, You will have a max total of 400 points.

When you do integer division of <400 / 400, you most likely will get an answer of 0.

You need to divide by 4 (total number of tests) rather than 400 (total possible points).

Also, realize that integer division will truncate the answer to the nearest integer rather than round. This is probably not a problem for you at this point, but soon you will want to learn about the differences between integer and floating point division.

Also, please don't continue to update the code in your initial post. It makes it difficult or impossible to understand the conversation below it. when you have new code, simply add a new post.
Topic archived. No new replies allowed.