Sunday, 25 August 2013

Display the output when type specifed word as first letter and ignore the other words after it

Display the output when type specifed word as first letter and ignore the
other words after it

After this question I figured out that using char as input will avoid the
infinite loops caused by typing characters for input which is using int.
But now I had met another problem.
When I typed the code below:
#include <iostream>
void language();
int main() {
language();
}
void language() {
char choice;
// Ask user for something and input
std::cout << "Press 1 to exit the program\n\n";
std::cin >> choice;
// Getting user's input and run the code below and find for specific
words
switch(choie) {
case '1':
std::cout << "\n\nEnding program...";
return 0;
break;
default:
std::cout << "\n\nPlease type the specific number.\n\n";
language();
break;
}
}
When I compile it I didn't get any errors or warnings. But when I type 12
or similar word with 1 at first, the program will be ended.
And before answering me, I still learning C++. (By the way I don't think I
really need to say this?) And because this I didn't know how to solve
this. What's happening to my code?

No comments:

Post a Comment