Problem with input
Question posted by: nrm
(Guest)
on
December 24th, 2005 10:05 PM
Ho, I'm having a problem when I run the following code, and enter the
name of the first candidate, after I press enter, the program skips the
chance to enter the second candidate's name. Anybody know a solution?
Thanks.
std::cout << "Please enter the name of the first candidate: ";
std::cin >> NameOne;
std::cout << "Please enter the name of the second candidate: ";
std::cin >> NameTwo;
2
Answers Posted
nrm wrote in message
<1135461457.918356.252640@g49g2000cwa.googlegroups. com>...[color=blue]
>Ho, I'm having a problem when I run the following code, and enter the
>name of the first candidate, after I press enter, the program skips the
>chance to enter the second candidate's name. Anybody know a solution?
>Thanks.
>
> std::cout << "Please enter the name of the first candidate: ";
> std::cin >> NameOne;[/color]
// try (remove the [return] from the stream):
std::cin.ignore();
[color=blue]
> std::cout << "Please enter the name of the second candidate: ";
> std::cin >> NameTwo;
>[/color]
--
Bob R
POVrookie
BobR <RemoveBadBobR@worldnet.att.net> wrote:[color=blue]
>
> nrm wrote in message
> <1135461457.918356.252640@g49g2000cwa.googlegroups. com>...[color=green]
>>Ho, I'm having a problem when I run the following code, and enter the
>>name of the first candidate, after I press enter, the program skips the
>>chance to enter the second candidate's name. Anybody know a solution?
>>Thanks.
>>
>> std::cout << "Please enter the name of the first candidate: ";
>> std::cin >> NameOne;[/color]
>
> // try (remove the [return] from the stream):
> std::cin.ignore();
>[color=green]
>> std::cout << "Please enter the name of the second candidate: ";
>> std::cin >> NameTwo;[/color][/color]
Also, if the name has spaces in it, you may want to look into using
std::getline()
--
Marcus Kwok
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 196,949 network members.
Top Community Contributors
|