Message from C, C++ discussions

November 2019

— I guess you want to run the loop as long the input is valid :) so in this case you should do

while(scanf("%i", &somenum) == 1)

Message permanent page

— 

The while loop runs as long as one input value is succesfully parsed and assigned - that should be it

— Thank you

— Haha ^^ your welcome

— Is it possible to use an if statement instead of a while loop?

— If scanf equals to 1 else …

— Sure for example:

if(scanf("%i", &somenum)) { 
//Okay
} else {
//Dammit something went wrong
}
the == 1 is implicit because 0 evaluates to false and everything else to true so 1 is true

Message permanent page

— Nice

— reinterpret_cast how long you have been coding for ?

— I started when I was 11 and I´m 18 now so 7 years ^^ and every day at least 3 hours - I´m crazy 😂

— And you?

— Not very long but i been coding mostly everyday