c++ - Temp Convert input bulletproofing? -
I am trying to write code which takes a lower limit and a higher limit (in Celsius) and incremental, and a table Shows the conversion in Fahrenheit anyway where I have a problem, it is bulletproofing of input.
This is my code
int main () {double less limit = 0; Double high limit = 0; Double phase = 0; Cout & lt; & Lt; "Please lower limit, boundary and gt; = 0: 10 \ n \ n"; CIN & gt; & Gt; LOWERLIMIT; While (((Cin> gt; & gt; lower limit)} lower limit and 0; lower limit> 500) {cout & lt; & Lt; "Invalid input! \ N"; Cin.clear (); Cin.ignore (numeric_limits & lt; int & gt; ::), '\ n'); } Cout & lt; & Lt; "Please give it in a higher limit, 10 & gt; range & lt; = 500: 20 \ n \ n"; CIN & gt; & Gt; HighLimit; While (((Cin & gt; & gt; higher limit)) higher limit & lt; = 10 || higher limit> 500) {cout & lt; & Lt; "Invalid input! \ N"; Cin.clear (); Cin.ignore (numeric_limits & lt; int & gt; ::), '\ n'); } Cout & lt; & Lt; "Please give it in one step. 0 <10: 4 \ n \ n"; CIN & gt; & Gt; Step; While (! (Cin & gt; & gt; Step) || step & lt; = 0; Phase & gt; 10) {cout & lt; & Lt; "Invalid input! \ N"; Cin.clear (); Cin.ignore (numeric_limits & lt; int & gt; :: max ;, '\ n'); } Cout & lt; & Lt; LowerLimit & lt; & Lt; Highlight & lt; & Lt; Steps & lt; & Lt; "\ N \ n"; The court's & lt; & Lt; "Thank you!"; Return 1; } output looks
< / P>
What happens is that it asks me for a lower limit, when I type something it does nothing, it just remains there when I write it continues. So when I put an 8, nothing happened, so I put it 0. With the higher limit I Type 10, nothing happens if I type 100 and it continues.
Feel the nervousness, understand what to do, I tried different loops and if the statements did not work.
Not the last digit, it is not HW
I do not have to tell you that I do not want to write this, I need to understand what is going wrong.
If you think I should say something you people will comment on it and I will edit, please do not just give 1 and leave it.
Remove cin after each first . What you are currently doing is that once you get the input again, because in the is also the condition of cin , you need to re-input this Input type two times
Comments
Post a Comment