Avatar of Sargie93
Sargie93
 asked on

Options

Hey, sorry if you've already seen/helped me with this, but I have additions I want to make to the program. The program kind of works like a log in system, you enter one of two names and a welcome screen is output, anything else and it's access denied. What I want to do now is make it so that each name has a different welcome screen.

This is the code I've already got which includes what I've added in an attempt to make this possible, although what I've done has had virtually 0 effect.

Thank you. :)

#include <Windows.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cmath>
#include <conio.h>

using namespace std;

struct first

{
      string user;

};

struct second

{
	string user;

};

void WelcomeUser(const struct first& A)
{
  string fname;
  size_t pos = A.user.find(' '); // locate blank

  if (string::npos == pos) // no blank?
  {
    cout << "Welcome " << A.user; // OK, full name
  }

  fname = A.user.substr(0,pos); // extract first name

cout << "Welcome " << fname;
}

void WelcomeUser(const struct second& B)
{
  string fname;
  size_t pos = B.user.find(' '); // locate blank

  if (string::npos == pos) // no blank?
  {
    cout << "Hello " << B.user; // OK, full name
  }

  fname = B.user.substr(0,pos); // extract first name

cout << "Hello " << fname;
}

 int main()

 {
      system("color 0F");

      struct first A;
	  struct second B;

	  cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
	  cout << "                               Press Enter";
	  cin.ignore();
	  system("CLS");

      cout << "Initiating Program..." << endl;
      Sleep (1000);
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "NOW LOADING...:  ";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      system("CLS");
      cout << "Please Verify Your Name..." << endl;
	  getline(cin, A.user); 
	  getline(cin, B.user);

      
bool correctName=false;
while(!correctName)
{

      //Set A.user here...

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

            cout << "" << endl;
            cout << "Program Now Processing...Please Wait..." << endl;
            Sleep (2000);
            Sleep (1000);
            cout << "Verification Complete..." << endl;
            Sleep (2000);
            Sleep (1000);
            system ("CLS");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
            cout << "Access Granted..." << endl;
            Sleep (2000);
            Sleep (1000);
            system("CLS");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
            WelcomeUser(A);
			cout << "" << endl;
            Sleep (2000);
            Sleep (1000);
            system("pause");
            return 0;

      }
        else
        {
        cout << "" << endl;
            cout << "Program Processing. Please Wait..." << endl;
            Sleep (2000);
            Sleep (1000);
            system("CLS");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
            cout << "Access Denied..." << endl;
            Sleep (2000);
            Sleep (1000);
            cout << "" << endl;
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
            cout << "Please Enter Your Full Name" << endl;
            cout << "" << endl;
            getline(cin, A.user); 
			getline(cin ,B.user);
      }

}

}
                                            

Open in new window

C++

Avatar of undefined
Last Comment
Sargie93

8/22/2022 - Mon
jkr

In which way do you want them to be different? You could just do something like

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

            cout << "" << endl;
            cout << "Program Now Processing...Please Wait..." << endl;
            Sleep (2000);
            Sleep (1000);
            cout << "Verification Complete..." << endl;
            Sleep (2000);
            Sleep (1000);
            system ("CLS");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
            cout << "Access Granted..." << endl;
            Sleep (2000);
            Sleep (1000);
            system("CLS");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
            WelcomeUser(A);
			cout << "" << endl;
            Sleep (2000);
            Sleep (1000);
            system("pause");
            return 0;

      }

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

            cout << "" << endl;
            cout << "Program Now Processing...Please Wait..." << endl;
            Sleep (2000);
            Sleep (1000);
            cout << "Verification Complete..." << endl;
            Sleep (2000);
            Sleep (1000);
            system ("CLS");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
            cout << "Access Granted..." << endl;
            Sleep (2000);
            Sleep (1000);
            system("CLS");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
            WelcomeUser(A);
			cout << "" << endl;
            Sleep (2000);
            Sleep (1000);
            system("pause");
            return 0;

      }


        cout << "" << endl;
            cout << "Program Processing. Please Wait..." << endl;
            Sleep (2000);
            Sleep (1000);
            system("CLS");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
            cout << "Access Denied..." << endl;
            Sleep (2000);
            Sleep (1000);
            cout << "" << endl;
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
            cout << "Please Enter Your Full Name" << endl;
            cout << "" << endl;
            getline(cin, A.user); 
			getline(cin ,B.user);

Open in new window


and change the code blocks individually.
Sargie93

ASKER
I know feel ever so slightly silly..... That worked well thank you. Now I've used this code as the second welcome screen:

void WelcomeUser(const struct second& B)
{
  string fname;
  size_t pos = B.user.find(' '); // locate blank

  if (string::npos == pos) // no blank?
  {
    cout << "Hello " << B.user; // OK, full name
  }

  fname = B.user.substr(0,pos); // extract first name

cout << "Hello " << fname;
}

Open in new window


It works, the only thing is instead of outputting "Hello Mike", I get "Hello Hello".

Any Ideas?
jkr

Hmm, there is no need to define two different structures that basically hold the same - nor in your case even the need to use a 2nd one. Aside from this , is there any "Hello" in the input?
Your help has saved me hundreds of hours of internet surfing.
fblack61
Sargie93

ASKER
Yeah I know that, see what I'm making is a kind of.....puzzle for someone, I'm going to change it so there are messages on each welcome screen which are going to be different depending on cin. And no there's now a hello in the input, just cout.

void WelcomeUser(const struct second& B)
{
  string fname;
  size_t pos = B.user.find(' '); // locate blank

  if (string::npos == pos) // no blank?
  {
    cout << "Hello " << B.user; // OK, full name
  }

  fname = B.user.substr(0,pos); // extract first name

cout << "Hello " << fname;
}

Open in new window

jkr

Hmm, OK. May I ask for the complete code again? ;o)
Sargie93

ASKER
Haha no problem :)

#include <Windows.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cmath>
#include <conio.h>

using namespace std;

struct first

{
      string user;

};

struct second

{
	string user;

};

void WelcomeUser(const struct first& A)
{
  string fname;
  size_t pos = A.user.find(' '); // locate blank

  if (string::npos == pos) // no blank?
  {
    cout << "Welcome " << A.user; // OK, full name
  }

  fname = A.user.substr(0,pos); // extract first name

cout << "Welcome " << fname;
}

void WelcomeUser(const struct second& B)
{
  string fname;
  size_t pos = B.user.find(' '); // locate blank

  if (string::npos == pos) // no blank?
  {
    cout << "Hello " << B.user; // OK, full name
  }

  fname = B.user.substr(0,pos); // extract first name

cout << "Hello " << fname;
}

 int main()

 {
      system("color 0F");

      struct first A;
	  struct second B;

	  cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
	  cout << "                               Press Enter";
	  cin.ignore();
	  system("CLS");

      cout << "Initiating Program..." << endl;
      Sleep (1000);
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "" << endl;
      cout << "NOW LOADING...:  ";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      Sleep (500);
      cout << "|";
      system("CLS");
      cout << "Please Verify Your Name..." << endl;
	  getline(cin, A.user);

      
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 << "Verification Complete..." << endl;
            Sleep (2000);
            Sleep (1000);
            system ("CLS");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
            cout << "Access Granted..." << endl;
            Sleep (2000);
            Sleep (1000);
            system("CLS");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
            WelcomeUser(A);
			cout << "" << endl;
            Sleep (2000);
            Sleep (1000);
            system("pause");
            return 0;

      }

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

            cout << "" << endl;
            cout << "Program Now Processing...Please Wait..." << endl;
            Sleep (2000);
            Sleep (1000);
            cout << "Verification Complete..." << endl;
            Sleep (2000);
            Sleep (1000);
            system ("CLS");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
            cout << "Access Granted..." << endl;
            Sleep (2000);
            Sleep (1000);
            system("CLS");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
            WelcomeUser(B);
			cout << "" << endl;
            Sleep (2000);
            Sleep (1000);
            system("pause");
            return 0;
	  }
        else
        {
        cout << "" << endl;
            cout << "Program Processing. Please Wait..." << endl;
            Sleep (2000);
            Sleep (1000);
            system("CLS");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
            cout << "Access Denied..." << endl;
            Sleep (2000);
            Sleep (1000);
            cout << "" << endl;
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
            cout << "Please Enter Your Full Name" << endl;
            cout << "" << endl;
            getline(cin, A.user);
      }

}

}
                                            

Open in new window


By the way, you've been an absolute saint helping me today, I don't really know how this site works, but it there is any way in which you can get some extra credit or something please let me know :)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
jkr

The problem is line 200 - you are calling 'WelcomeUser(B);' while only 'A' is set to a valid input value and should be used here.
Sargie93

ASKER
Oh yeah! I see it, so is there any way in which I can make B valid?
ASKER CERTIFIED SOLUTION
jkr

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
Perfect, thank you once again JKR
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy