repl.it
@ArlanPereira/

Login script in a function

C++

No description

fork
loading
Files
  • main.cpp
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>
using namespace std;

//global variable
string globalUsername = "Boris";
string globalPassword = "Paris";
//function to check login details
bool checkLogin(){
  //local variable
  string usernameEntered;
  string passwordEntered;
  cout << "Enter your username: " << endl;
  cin >> usernameEntered;
  cout << "Enter your username: " << endl;
  cin >> passwordEntered;
      if(usernameEntered == globalUsername && passwordEntered == globalPassword){
        cout << "Login Successful" << endl;
      }else{
        cout << "Login Unsuccessful" << endl;
      }
}
//main function
int main() {
  //local variable
  bool loginResult;
  loginResult = checkLogin();
  cout << loginResult;
}