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.
38 messages · Page 1 of 1 (latest)
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.
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?
can you help me figure out a way to make this work?
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
what is a fancy function?
basically anything lol
so is cout << a fancy function
no
?
are you just being rhetorical?
or was there a reason you asked that question?
it is kind of fancy
look i cant help the restrictions i am under.. are you willing to help out or no?
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
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
and if i do not enter integers, it defo trips the error, but infinite loops .. how can i get it to not do that and read the new cin?
https://en.cppreference.com/w/cpp/io/basic_ios/clear call this to clear the error flags
https://en.cppreference.com/w/cpp/io/basic_istream/ignore call this to ignore characters up to some specified character (probably \n is what you want to clear the entire line)
i can't use either of those :/
what functions can you actually use then
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
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
well what was taught in class then
basically what ms is saying
but i dont know if cin needs still to be cleared
;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'); } } }
1
2
3
here is a simple example of reading many integers in a loop