Hi there.
I started writing some c++ codes a week ago and I run into this issue.
I wanna write a bmi calculator and this piece of code gives me problems.
It should work like a COPPA screen for a kids game, allowing you to input only numbers between a chosen range and no other characters.
Before introducing the (!(cin >> w)){cin.clear();cin.ignore(numeric_limits<streamsize>::max(), '\n');} condition when the user entered anything else than a number the program would enter a loop and crash. Now it does't allow the user to input other characters but it does't recognize the range.
Please help me. Thank you
Really , i totally disagree with that , maybe what might be giving you the notion that it's taking spaces is that ' ' between the colon in your prompt... cout << "Your weight is: "; ///: "; this might be it. but doubles or other integral types will never accept spaces as input.
Guuuuuuyyyyyyyyysssssss, He just means that. You can press space , then enter 55.
1 2 3
double x;
cin >> x;
cout << x;
input : " 55" (with a space before entering the numbers as you see, he wants the program to not let the user enter any spaces, what OP doesnt get, is that the space is not taken as an input. My thoughts about this continue at the end of this post.)
output:
55
(It continues here ->) What Im wondering is, why OP gives a shit.
Well @grui_sanger You cant get around that. Because the spaces are not taken in as input, so the program cant react to that in the first place. Because the program doesnt even recognize the spaces.