Log in system error

I cant seem to be able to make a new user and i cant seem to log in it just says invalid login all help would be appreciated.

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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<fstream>
#include <string>
using namespace std;	



void welcomeScreen()
{
	cout << "===============================================" << endl;
	cout << ""<< endl;
	cout << "Welcome to The Box warehouse" << endl;
	cout << "" << endl;
	cout << "===============================================" << endl;
	
}
void mainmenu()
{
		
	

	cout << "Enter # 1 for Register" << endl;
	cout << "Enter # 2 for To login" << endl;
	cout << "" << endl;
	cout << "Enter a number your options: "<< endl;

	int xin;
	cin >> xin;
	system("CLS");

if (xin == 1)
	{
		cout << "Thank You For Choosing The Box Warehouse" << endl;
		void reg();
		
	}

	else if (xin == 2)
	{
		cout << "Please Log in\n" << endl;
		void LoginScreen();

	}
}
void LoginScreen()


{
	int ans, tries;
    tries = 0;
    string newUser, newPass, goodUser, goodPass, _pass, _user;
    string pass2, user2;

        system("CLS");
        cout<<"Enter Username: ";
        cin >> goodUser;
        cout<<"Enter Password: ";
        cin >> goodPass;
    
        //Read Data from Text File
        ifstream new2_data;
        new2_data.open("users.txt");
        //char output[100];
      
    
        //Verify Data from Text File
        if (goodUser == _user & goodPass == _pass)
        {
            cout<<"Login Successful!  Please enjoy our services!\n";
            system("pause");
            void mymenu();
        }
        else
        {
            if (tries < 3)
            {
            cout<<"Invalid Login!  Please try again.\n";
            system("pause");
            tries++;
            void reg();
            }
            else
            {
            cout<<"Invalid Login!\n";
            system("pause");
            
            }
		}
}




void reg()
{
 string newUser, newPass, goodUser, goodPass, _pass, _user;
 string pass2, user2;
 
 
  system("CLS");
		 cout<<"Enter New Username: ";
        cin >> newUser;
        cout<<"Enter New Password: ";
        cin >> newPass;

    //Write User Info to F;ile
    ofstream new_data("users.txt");
	
    new_data <<"" << newUser
             <<"" << newPass << endl;
    new_data.close();

	cout<<"Thanks For Regestering With The Box Warehouse";
	LoginScreen();
}

char myMenu()
{
	cout << "Enter # 1 for Box size" << endl;
	cout << "Enter # 2 for Box Quality" << endl;
	cout << "Enter # 3 for Colour Of Box" << endl;
	cout << "Enter # 4 to Number of Boxes" << endl;
	cout << "Enter # 5 to Exit" << endl;
	cout << "" << endl;
	cout << "Enter a number to continue" << endl;

	int xin;;
	cin >> xin;
	system("CLS");

	if (xin == 1)
	{
		cout << "Entering Deposits section\n" << endl;
		return myMenu();
	}

	else if (xin == 2)
	{
		cout << "Entering Withdrawals section\n" << endl;
		return myMenu();
	}

	else if (xin == 3)
	{
		cout << "Entering Transfers section\n" << endl;
		return myMenu();
	}

	else if (xin == 4)
	{
		cout<< "Entering Balance section\n" << endl;
		return myMenu();
	}

	else if (xin == 5)
	{
		cout << "Exiting from the program\n" << endl;
		return myMenu();
	}

	else
	{
		cout << "Invalid Entry!\n" << endl;
		return myMenu();
	}	
	
	system ("pause");
}


int main()
{
	welcomeScreen();
	mainmenu();
	reg();
	LoginScreen();
	myMenu();
	
	return 0;
}
Line#69, you should have && not &
I have now changed that but still doesnt work.
on line 36, 43 etc.: this are function declarations they're not called
I dont understand i thought they called the function i want to use.
do i just delete the void part?
@Dan Goodridge - have you attempted to debug it yourself?
Last edited on
closed account (Dy7SLyTq)
@dan: yes
Between lines #66 and #69 although you have opened the file you have done nothing with it, as a result the local variables _user and _pass are empty strings, hence the comparisen returns false for both and puts you down into the else block.

I suggest that you put a delimiter between your fields in the users.txt file. Why are you using a txt file anyway? It would be better to store your data as a bytstream, if you must store it otherwise there isn't any need for the users to enter credentials when someone else can just open the file and see what the cre4dentials are.

Does that help?
Last edited on
do i just delete the void part?
that would make it a function call indeed. But since you haven't previously declared the compiler will complain.

So put all declaration before the first implementation (before line 10). Then remove the types in front of what is intended a function call.

Line 43 is a declaration. Line 116 is a function call.

For instance:

1
2
int f(); // is a declaration
int x = f(); // is a function call 
im using a text files because thats what i was shown on my course. I have tried debugging myself.
You're also overwriting the file everytime someone registers. Find out how to open an existing file if it exists and to append to it. You need to obviscate the data in the file to stop someone from just reading the contents and logging in as someone else.
I have now sorted out the registering part i can add new users without them deleting the user before thats brilliant im getting somewhere now just the log in part. Ive added this to get it to read from file but still doesnt work.

1
2
3
4
5
6
   if (new2_data.is_open())
        {
            
           cout << new2_data,_user;
           cout << new2_data,_pass;
        }
Well that's not going to read the file contents into your local variables, which is what I guess you intended. It's just going to write the address of the ifstream variable to the std output i.e. the screen! How were you instructed to read data from a file?
Ive spoke to teacher today an has said he wants the text file data displayed on screen using classes. How do i do that? I have don this so far and i am very stuck. Also thanks for all the help so far.

Done this much.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class order
{
private:
	int acc;
	string Boxsize;
	string Boxquality;
	string Boxcolour;
	string Boxnumber;
public:
	void importDetails(int, string, string, string);
	void displayorder(void);
	order(void);
	~order(void);
}

void order :: displayorder(void)
{
	cout << "Account Number: " << acc << endl;
	cout << "Box quality: " << Boxquality << endl;
	cout << "Box Colour: " << Boxcolour << endl;
	cout << "Number Of Boxes: " << Boxnumber << endl;
	cout << endl;
}


but where do i go from here ?
Last edited on
Topic archived. No new replies allowed.