Neil Zanella wrote:
> Sure I will. Here is the code. Uncommenting the lines for case 1 produces
> the compiler error message.
Try moving them before the 'default'
> Furthermore, out of curiosity, as an unrelated
> matter, I am quite interested in knowing how come the program starts looping
> when some large number is entered.
cin.fail() is set and all subsequent ">>" operations are ignored,
with x unmodified every time. Hence, if x happened to be non-zero,
the loop iterates infinitely.
>
> Thanks,
>
> Neil
>
> #include <iostream>
>
> int main() {
> unsigned int x; do {
> std::cout << "Please enter an integer: " << std::flush;
> std::cin >> x;
> switch (x) {
> case 0:
> std::cout << "Hello!" << std::endl;
> break;
> default:
> unsigned int y = ++x;
> std::cout << "You could have entered " << y;
> std::cout << ". Why didn't you?" << std::endl;
> break;
> //case 1:
> // std::cout << "What??? You entered one?" << std::endl;
> // break;
> }
> } while (x != 0);
> }
HTH,
- J.
|