0

I'm having difficulty with this part where there seems to always be another different problem whenever I solve one. The initial issue was that whenever I entered Y or y to loop the whole thing, it skips the first input which is Enter your name: and goes to Enter your address: . To stop that I tried putting cin >> name above getline(cin,name) and it did but introduced a new problem which would replace the first word of the string. Is there anyway to solve the issue of both the skipping of the first input and the replacement of the first word?

do {

        cout << "Day: " << days << "\n\n";
        days++;

        cout << "Enter your name: " << endl;
        cin >> name;
        cin.ignore();
        getline(cin, name);
        data.setName(name);

        cout << data.getName() << "\n" << endl;

        cout << "Enter your address: " << endl;
        cin >> address;
        cin.ignore();
        getline(cin, address);
        data.setAddress(address);

        cout << data.getAddress() << "\n" << endl;

        cout << "Enter your email: " << endl;
        cin >> email;
        cin.ignore();
        getline(cin, email);
        data.setEmail(email);

        cout << data.getEmail() << "\n" << endl;

cout << "Press Y/y to continue to enter customer data. Otherwise press N/n to go to next day" << endl;
        cin >> c;
        cout << "\n" << endl;
    } while ((c == 'Y' || c == 'y'));
    

    return 0;
};

The output i got if i entered ab c d in name for example it would output just c d. So while it was helpful but it did not solve the problem of it skipping the first word. My desired output would be for it to display the string that was entered meaning in this example it would display ab c d.

Tristan
  • 1
  • 1

0 Answers0