Return

Sargie93
Sargie93 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
@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.

Author

Commented:
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.
Commented:
Put your code in a loop till you get the expected name

bool correctName=false;
while(!correctName)
{


      //Set A.user here...

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

            //do welcome stuffs.

      }
      else
      {
            //do other stuffs
      }
}

Author

Commented:
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

Author

Commented:
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?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial