Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

c++ programming problem?

I need to save 'name' and 'student number' as string and 'score' as a double. So I defined two 'string' and a 'double'.

But this problem exists: by using getline(cin,str), console does not wait me to enter 'score'. Because of using 'cin>>' after 'getline'.

What can I do?

4 Answers

Relevance
  • Ronald
    Lv 5
    1 decade ago
    Favorite Answer

    Getline leaves the new line in the input. The reason it doesn't wait is the cin >> that follows sees that newline from the previous entry. Do a "cin.ignore()" to swallow it up prior to prompting for your next input.

  • Anonymous
    1 decade ago

    Without viewing the source in question, I suspect you're asking for them all one one line?

    Try something like:

    cout << "Enter Name\n";

    cin >> NameVar;

    cout << "Enter SID\n";

    cin >> IDVar;

    cout << "Enter Score\n";

    cin >> ScoreVar;

  • 1 decade ago

    include <iostream>

    #include <string>

    using namespace std;

    string str;

    int i;

    double d;

    cout <<"name";

    cin >> str;

    cout << "student no:"

    cin >> i;

    cout <<"Enter score";

    cin >>d;

    Source(s): fixed from the previous answer from someone else
  • Anonymous
    1 decade ago

    string str;

    int i;

    double d;

    cout<<"name";

    cin>>str;

    cout<"student no:"

    cin>>i;

    cout<"Enter score";

    cin>>d;

    Sorry for any syntax errors i studied C 3 yrs ago

Still have questions? Get your answers by asking now.