#do while

38 messages · Page 1 of 1 (latest)

tough glacierBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

deft trench
#

!cin is true if an error was reached

#

so it will keep prompting you for more numbers

tacit ingot
#

i am limited on the commands i can use .. is there a "very fundamental" way to check if firstNumber is an integer that im just missing?

tacit ingot
#

i would like the while expression to check if firstNumber and secondNumebr are integers

#

but again i am limited as to what i can use .. no fancy functions

deft trench
#

what is a fancy function?

tacit ingot
#

basically anything lol

deft trench
#

so is cout << a fancy function

tacit ingot
#

no

tacit ingot
#

are you just being rhetorical?

#

or was there a reason you asked that question?

deft trench
#

it is kind of fancy

tacit ingot
#

look i cant help the restrictions i am under.. are you willing to help out or no?

deft trench
#

the error looks like you're just immediately trying to read the input again when it's already incorrect

#

so like if you input a, the a is still there

#

you never actually read the incorrect data or cleared the error

tacit ingot
#

i thought the new cin will try and read a new value when it loops

#

how can i get it to do this?

#

like if i do enter two integers, the program works fine

tacit ingot
deft trench
tacit ingot
#

i can't use either of those :/

deft trench
#

what functions can you actually use then

tacit ingot
#

im in cs 101 .. we did for loops last week, we are doing "what is a function" this week, and i cant use anything not taught in class

#

so while i know what you are saying and how it helps, i cant use it yet

#

i need to use some fundamental thing to validate this input as integers

austere flame
#

For each number (0, 1, 2, 3...) an if statement maybe?

#

and you use in your while loop true and a break if its a number

#

But that concept of your class is kinda retarted lol

deft trench
tacit ingot
#

basically what ms is saying

austere flame
#

but i dont know if cin needs still to be cleared

deft trench
#

;compile 1 a 2 b 3``````cpp #include<limits> #include<iostream> int main(){ int x=-1; for(;;){ std::cin>>x; if(std::cin){ std::cout<<x<<'\n'; if(std::cin.eof()){ break; } }else if(std::cin.eof()||std::cin.bad()){ break; }else{ std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n'); } } }

long glenBOT
#
Program Output
1
2
3
deft trench
#

here is a simple example of reading many integers in a loop