0

I been at it for hours now trying to figure out why my code isnt letting me renter in my name after I say I want to register again heres the code:

#include <iostream>
#include <string>

using namespace std;

int main() {
    string full_name{};
    string answer{"yes"};
    

    while (answer1 == "yes" || answer1 == "Yes") {
        string answer{};

        cout << "Type your full name with a space inbetween: ";
        getline(cin, full_name);

        cout << full_name << " has been registered" << endl;

        cout << "Do you want to clear your name from the list :";
        cin >> answer;

        if (answer == "yes" || answer == "Yes") {
            full_name.clear();
        }
        else if (answer == "no" || answer == "No") {
            cout << "Your name is still in the list" << endl;
        }

        cout << full_name << endl;

        string answer1{};
        cout << "\nDo you want to register again or someones else name?" << endl;
        cin >> answer1;

        cout << endl;

        if (answer1 == "no" || answer1 == "No") {
            cout << "Thank you for registering" << endl;
            break;
        }
    }
}

When I say yes to cout << "\nDo you want to register again or someones else name?" << endl; it loops back up but skips cout << "Type your full name with a space inbetween: "; getline(cin, full_name); I provided images of what I meanenter image description here

Mario
  • 1
  • Let me know if I should add comments to the code I forgot to do that before I posted the question. – Mario May 18 '21 at 19:18
  • A good way to avoid having to heavily comment code is to write code that describes itself by using descriptive identifiers, avoiding convoluted code, and resisting the urge to pack too much code into one line. You've managed this for the most part, but reusing `answer` could (and in this case does-- `answer1` doesn't exist at the first `while` loop) lead to confusion. – user4581301 May 18 '21 at 19:32

0 Answers0