help with a while loop using sentinel

The purpose of the program is to use a function to read multiple inputs of "homework grades" and then calculate the weighted score for the homework and return the score.

Supposedly the user would need to indicate that they're done with the input process, so I thought using a sentinel would be the way to go. My problem is that it's not acknowledging it therefore not calculating the grades as I want it to. I think the rest is correct, but maybe the placing of some things are wrong? Not sure what else is the problem.

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
#include <stdio.h>

int homework(int hwscore, int hwmax, int hwweigh);

int main()
{
	int hwscore, hwmax, hwweigh;
	printf("Enter homework grade and maximum possible score as follows: grade max_score\n");
	homework(hwscore, hwmax, hwweigh);

	return 0;
}

int homework(int hwscore, int hwmax, int hwweigh)
{

	while(hwscore!=0&&hwmax!=0)
	{
	scanf("%d %d\n", &hwscore, &hwmax);
	
	}

	hwscore=hwscore+hwscore;
	hwmax=hwmax+hwmax;
	hwweigh=(hwscore*50)/hwmax;
	printf("%d",hwweigh);
	
	return 0;

}
Last edited on
Line 7: hwscore, hwweigh and hwmax are all uninitialized variables.

Line 17: You're testing uninitialized variables.

Line 24,25: You're calculating hwmax based on an uninitialized variable.

Topic archived. No new replies allowed.