Simple Log-in System

Code Review?

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
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
using namespace std;
int main(){
    string username;
    string password;
    cout << "Username: ";
    cin >> username;
    cout << "Password: ";
    cin >> password;
    system("cls");
    if(username=="xcalibur0645"){
                                 if(password=="hotdog"){
                                                        cout << "Access valid.";
                                                        cout << "\n\n";
                                                        system("pause");
                                                        return 0;
                                                        }
                                 else{
                                      cout << "Access denied.\n";
                                      cout << "Wrong password.\n\n";
                                      system("pause");
                                      return 0;
                                      }
                                 }
    else{
         if(password=="hotdog"){
                                cout << "Access denied.\n";
                                cout << "Wrong username.\n\n";
                                system("pause");
                                return 0;
                                }
         else{
              cout << "Access denied.\n";
              cout << "Wrong username and password.\n\n";
              system("pause");
              return 0;
              }
         }
}


It is a simple access-granting program.
CODE REVIEW please?

Oh, and I'm just 12 years old, so kindly please talk in common words. LOL
Looks good :) Your coding is easily readable and organized.

Here's a few ideas:

After each test you have return 0; which quits the program. You could eventually use a while() loop that can keep the program going until the user presses a certain button to quit. Then you would have return 0; only at the very end - where it usually should be.

system("pause"); is bad in general. It takes a lot of resources and it not portable (ie: it sux). For c++ use cin.get() .

Oh and i meant to add that u shouldn't use system() at all. Cheers
Last edited on
Topic archived. No new replies allowed.