Hi everybody
I cannot understand why I cannot insert the second char variable.
The program goes from the first character input directly to the first integer input.
The program is written using codeBlocks 17.12.
Can anybody help me?
Cheers
Luca
Hi everybody
I cannot understand why I cannot insert the second char variable.
The program goes from the first character input directly to the first integer input.
The program is written using codeBlocks 17.12.
Can anybody help me?
Cheers
Luca
Why are you reading names as single chars rather than as strings?
Anyway, the problem is that when you enter the first char, that enter is read as the second char, so it is read before you can actually enter your second char.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Thanks for your reply.
If that is the problem, I cannot understand how to prevent it to happen while maintainig the structure of the program with those two distinct questions.
Btw I used char variables because I just ask 1 letter at the time.
Cheers
Luca
Basically, the idea is that you need to read and discard the newline from the enter. This can be done by changing the format string for reading the second char to add a leading space to match the whitespace:Originally Posted by Lucky Luka
Code:scanf(" %c", &last);
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
It works!
Thank you!
Cheers
Luca