sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
nrm's Avatar

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
BobR's Avatar
Guest - n/a Posts
#2: Re: Problem with input


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


Marcus Kwok's Avatar
Guest - n/a Posts
#3: Re: Problem with input

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
 
Not the answer you were looking for? Post your question . . .
196,949 members ready to help you find a solution.
Join Bytes.com

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.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors