![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Input validation: can only enter a number ranging from 0-300Okay, I'm a first-year student in C++ and I'm writing a program where a bowling team consisting of five players bowls three games. The program ask the user to enter the scores for the 5 individual players. When someone finished entering all the scores, the program takes the total score for each player and outputs the average. I got that part down.
What I'm having trouble with is the input validation. Someone can only enter a number ranging from 0-300. If someone enters a number higher or lower than that, the program ask the user the input the number again until is valid. I try doing it with an in statement but that fail because the program still counts the wrong number as part of the average. Also, when I enter two invalid numbers in a row, the program ignores the input range and keeps going. So, cna anyone help me, give me some pointer or different suggestion or point me in the right direction? I'll appreciate it. Here's my current crappy code: CPP / C++ / C Code:
... Yeah. |
|||
|
#2
|
|||
|
|||
Re: Input validation: can only enter a number ranging from 0-300Quote:
|
|
#3
|
|||
|
|||
Re: Input validation: can only enter a number ranging from 0-300Well I don't know, it looks to me like you'd want make sure this does not get done:
CPP / C++ / C Code:
It could be moved to after that input validation loop ocicat spoke of. Presently it's right in the middle or at least will get hit once.... Speaking of which, if you do the loop right , you should only need one: cin >> dblScores; |
Recent GIDBlog
Install Adobe Flash - Without Administrator Rights by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The