I need to write a program so the output will become like this:
How many students? 3
Student 1 mark : 987
INVALID
Student 1 mark : 25
Student 2 mark : 90
Student 2 mark : 65
Total pass: 2
Total fail: 1
The average mark is 60
I just made the source code but I stuck because the infinite loop..Here's my source code
There are no infinite loops in this program.I don't know how you got stuck!
(Maybe you think it as infinite because you are not outputting anything on screen)
I do not use printf and scanf and know very little about it.I use simple cin and cout.But printing INVALID continuously is not the preoblem with while loop.I think scanf do not take input.It just scans input stream.If so then you need to clear input buffer before using scanf.
@Nur Zafri
Welcome to the forum. Here are a few tips:
1- Do not title threads "need help"... Be more descriptive.
2- Do not use text message spellings. This is forum for learning and discussion, not a teenager chatroom service.
3- On the subject:
It is very easy to make a while loop malfunction, if you do not understand how C++ logic statements work. Like right there:
This appears to be a nested while loop. The inner loop, while(mark<0 || mark>100) would keep looping forever unless the break statement is used. In fact, I don't think there should be a control statement here. Use conditional (if...else) statement instead.
Edit: I might add that system("pause") is strongly advised against. Here: http://www.cplusplus.com/forum/articles/11153/
I would suggest that you use a hanging scanf() at the end, instead of system("pause")...
I tried if but not work. Maybe something wrong with my source code. Then, I compared mine with your source code. Now, I know all the mistakes I have done. Thank you so much akshit.