![]() |
Simple mistake but stuck
The code works but the percentages dont work correctly. They register has 0. A litle help needed please
Code:
/* Header.c */ |
Re: Simple mistake but stuck
Can you provide a bit more as to what is not working as looking at the total code seems not what I am enjoying without knowing what its suppose to do and what its doing.
|
Re: Simple mistake but stuck
Void Summary.
printf("Percentage of students with a D:> %d\n", DStudent); printf("Percentage of students with a M:> %d\n", MStudent); printf("Percentage of student with a P:> %d\n", PStudent); printf("Percentage of students with a F:> %d\n", FStudent); } It should display the percentage of students with that grade. But it displays 0 |
Re: Simple mistake but stuck
Any percentage less than 100 is a fraction. Are you trying to print that fraction as an integer? Just curious, looks that way from the snippet.
|
Re: Simple mistake but stuck
I'm trying to print the percentage of how many students got that grade.
e.g If 4 students took the exams 2 got Pass 2 got Merit Then Pass would be 50% Merit would be 50% I hope this clears things up. |
Re: Simple mistake but stuck
int Students = 4;
int Pass = 2; Pass/Students = 2 / 4 = ? (Zero, that's what. These are integers.) I hope this clears things up. |
Re: Simple mistake but stuck
DStudent=100*(Distinction/TStudent);
Try DStudent=(100*Distinction)/TStudent; |
Re: Simple mistake but stuck
That will work, so long as the category is at least 1% of the students. Four distinctions out of a thousand students would still fail, though. I would convert the category and the number of students to floats, do the division, and convert back. I would definitely multiply first, as Shabbir shows, since a larger numerator will usually result in more accuracy. Any piddling decimal fractions that occur will be truncated on the reconversion to int, or you could round.
|
Re: Simple mistake but stuck
Thank you for clearing that up. Much appreciated.
|
| All times are GMT +5.5. The time now is 07:22. |