Problem with input

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nrm

    #1

    Problem with input

    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;

  • BobR

    #2
    Re: Problem with input


    nrm wrote in message
    <1135461457.918 356.252640@g49g 2000cwa.googleg roups.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


    Comment

    • Marcus Kwok

      #3
      Re: Problem with input

      BobR <RemoveBadBobR@ worldnet.att.ne t> wrote:[color=blue]
      >
      > nrm wrote in message
      > <1135461457.918 356.252640@g49g 2000cwa.googleg roups.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

      Comment

      Working...