login, signup program

Hello, I am trying to figure out why my code is not working. It is a simple login and signup program. My problem is that the "while" function on Line: 66 does not work and gives me an error when I run it. There are 2 .txt files which store the usernames and passwords. The program is compiling successfully but the crashes when I try to log in.

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include <string>
#include <windows.h>
#include <fstream>
#include <conio.h>
#include <stdio.h>

#include "clrscr.h"// allows me to use clrscr();Made it myself, it just clears the screen and does system("pause")

using namespace std;

int main()
{
    int i = 0;

    string user, chuser[99];
    string pass, chpass[99];
    string llos;
    string los;
    string suser;
    string spass;

    fstream unm("name.txt");
    fstream pwd("pass.txt");

    SetConsoleTitle("ICG SECURITY");
    cout << "Welcome to ICG Security System." << endl;
    Sleep(1000);
a:
    cout << "LOGIN or SIGNUP:" << endl;
    cin >> los;
    if (los == "signup" || los == "SIGNUP" || los == "Signup")
    {

        cout << "Please type in your new username:" << endl;
        cin >> suser;
        unm << suser << endl;
        cout << "Please type in your new password:" << endl;
        cin >> spass;
        pwd << spass << endl;
        cout << "You have successfully Signed Up to ICG.\nClose the program and login!\n" << endl;
		unm.close();
		pwd.close();
        Sleep(3000);
        clrscr();
        goto a;
    }
    else
    {
        goto b;
    }

	if (!(unm)){
		perror("File info");
	}
	if (!(pwd)){
		perror("File info");
	}

    cin >> llos;
    if (llos == "login" || llos == "LOGIN" || llos == "Login")
    {
b:
        cout << "Please type in your username:" << endl;
        cin >> user;
        while (unm)// around here is the error I get
        {
	unm >> chuser[i];

	if (user == chuser[i])
            {
                cout << "Please type in your password:" << endl;
                cin >> pass;
		i = 0;
                while (pwd)
                {
	         pwd >> chuser[i];
                    
                    if (pass == chpass[i])
                    {
                        cout << "LOGIN COMPLETE!" << endl;
                        Sleep(2000);
                        clrscr();
                        goto a;
                    }
		i++;
                }
            }
	i++;
        }
    }
    else
    {
        cout << "Invalid Details" << endl;
        Sleep(2000);
        clrscr();
        goto a;
    }
	clrscr();
    return 0;
}
First, you're not checking all possibilites (ex.: what if signup was SiGnUP?).
Second, you're using goto when you could only use while.
Third, you're not checking "login". The goto goes directly to b label, after the if. So you made 52-62 for nothing: your code will never reach them.
Fourth, using while with a stream (casting it to a bool) says if it is good for reading/manipulation. That's probably your error.
Fifth: you're using C libraries when you could only use C++ libraries. That's an awful practice.
Last edited on
Topic archived. No new replies allowed.