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
Avatar of Sargie93
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.
Avatar of Sargie93
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
Avatar of pradhanv
pradhanv
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Sargie93
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
Avatar of Sargie93
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?
C++
C++

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

58K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo