Avatar of Sargie93
Sargie93
 asked on

Return

I'm pretty new with C++ so I'm not very sure on all the "lingo", but any help is appreciated.

This is the IF statement from my program:

if (A.user == "Josh Sarge")

      {
            cout << "" << endl;
            cout << "Program Now Processing...Please Wait..." << endl;
            Sleep (2000);
            Sleep (1000);
            cout << "Name Is Correct" << endl;
            cout << "" << endl;
            Sleep (2000);
            cout << "Welcome Josh!" << endl;
            system("pause");
      }

      else

      {
            cout << "" << endl;
            cout << "Program Processing. Please Wait..." << endl;
            Sleep (2000);
            Sleep (1000);
            cout << "Please Enter Your Full Name" << endl;
            cout << "" << endl;
            
      }

};

Now it does work if the name is correct, but I want the program to loop back if it's wrong. So basically, if someone entered the wrong name, the program would say "Please Enter Your Full Name" until the correct name was input.

Thank you.

God Bless
C++

Avatar of undefined
Last Comment
Sargie93

8/22/2022 - Mon
Sargie93

ASKER
@Orcbighter.

Thank you for your response, when I use your code, I get these errors:

error C2059: syntax error : ')'
error C2143: syntax error : missing ';' before '{'

I'm probably doing something stupid, but I don't know what to do with it now.
Sargie93

ASKER
Oh I'm sorry, I didn't realize that had to be clarified. This isn't academic, it's simply me getting interested in coding. I did basics of it in college a couple of years ago but never stuck with it so I' teaching myself again. This isn't for any formal study.
ASKER CERTIFIED SOLUTION
pradhanv

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Sargie93

ASKER
Okay so I have changed the code and this is what I've got:

bool correctName=false;
while(!correctName)
{

      //Set A.user here...

      if (A.user == "Josh Sarge")
      {
            correctName=true;

            cout << "" << endl;
            cout << "Program Now Processing...Please Wait..." << endl;
            Sleep (2000);
            Sleep (1000);
            cout << "Name Is Correct..." << endl;
            Sleep (2000);
            Sleep (1000);
            cout << "Welcome Josh" << endl;
            system("pause");
            return 0;

      }
      else
      {
        cout << "" << endl;
            cout << "Program Processing. Please Wait..." << endl;
            Sleep (2000);
            Sleep (1000);
            cout << "Please Enter Your Full Name" << endl;
            cout << "" << endl;
      }

}

}

It works for the correct name, but when I input and incorrect name it just repeats this bit:

 else
      {
        cout << "" << endl;
            cout << "Program Processing. Please Wait..." << endl;
            Sleep (2000);
            Sleep (1000);
            cout << "Please Enter Your Full Name" << endl;
            cout << "" << endl;
      }

over and over again
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Sargie93

ASKER
Okay so I've got it to work properly (thanks @Pradhanv) , now what if I wanted to add another "user", so Josh Sarge is the correct name, is there another way to make Mike Sarge the correct name too but output something else?