Hi, so I'm new to the forum. My name is Alex, I am currently learning C/C++ off of the website: www.learncpp.com. I am fairly new at programming, only about a week or two into coding. With that said, I am an eager learner and need some help with a practice program I am developing.
I cannot seem to get the Registration() function to properly execute the Login() function when the user chooses that they are a returning user. It is explained a little more in detail with the comments of the code.
/* Employee Registry Program.cpp :
Expected results of this program:
Asks the user if they are new or returning.
Choosing "new" will direct the user to registration, where the user will
input a chosen username and password, which will be saved into a directory.
Choosing "returning" will direct the user to the login screen where they
will input a valid username and password.
After the user is logged in, the program will display a menu of actions the
user would like to perform.
*/
#include "stdafx.h"
#include <iostream>
#include <string>
#include <conio.h>
usingnamespace std;
/*
Login() asks the user to enter a valid username and password. If the user
fails to enter a valid username and password the function informs the user
of the failure to login and reexecutes.
*/
void Login()
{
string LogPassword;
string LogUsername;
TryAgain:
cout << "Please enter the your username: " << endl;
cin >> LogUsername;
cout << "\n";
cout << "Please enter your password: " << endl;
cin >> LogPassword;
cout << "\n";
if (LogPassword=="user" && LogUsername=="password")
{
cout << "Login credentials accepted." << endl;
cout << "\n";
}
else
{
cout << "Login credentials denied. Please try again." << endl;
cout << "\n";
goto TryAgain;
}
}
/*
Registration() asks the user if they are new or returning. If "new,
the function directs them to registration. If "returning" the
function directs the user to the login screen. [Login()]
Problem: Cannot get function to execute Login() function if user is
"returning".
*/
void Registration()
{
string RegResponse;
cout << "Are you a new or returning user?" << endl;
cin >> RegResponse;
if (RegResponse=="new"||"New"||"NEW")
{
string RegUsername;
string RegPassword;
cout << "Please choose and enter a username:" << endl;
cin >> RegUsername;
cout << "\n";
cout << "Please choose and enter a password:" << endl;
cin >> RegPassword;
cout << "\n";
cout << "Thank you for registering, you may proceed to the login screen." << endl;
cout << "\n";
}
else (RegResponse=="returning"||"Returning"||"RETURNING");
{
Login();
}
}
int main()
{
cout << "Welcome to <insert company name>." << endl;
Registration();
cout << "Welcome, <user>, to <insert company name>'s employee registry." << endl;
system ("PAUSE");
return 0;
}
Say I wanted to add a error message to this program that informs the user of the invalid input and re-executes Registration() when the user does not enter either 'new' or 'returning'...
...how would I go about adding that into the function. I've tried adding another else if statement but that is illegal. I've tried adding another if statement but it doesn't seem that the compiler ever recognizes this statement.
It's best not to use goto since it's been deprecated along time ago. It's still around to allow backwards compatibility for legacy programs. Instead, use something like this:
Ah ok, thank you so much I'll be sure to remember that advice regarding goto. A while statement, of course. Thanks, I'm trying to self-study C++ and finding it difficult seeing as how there is no one around (irl) to discuss the topic with, but with the help of this forum and a lot of practice I should have it down in no time.