Problem with my code [Help Requested]

Hello!

I'm experiencing an issue with my code below. What happens, is that after the user enter an account name, all the cout are being ran, and then the program exit (see screenshot below).
http://imgur.com/CYdJGRS

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
//bankaccount system with reg and login system (one time use)
#include <iostream>
using namespace std;

int main()
{
	//register
	cout << "Welcome Jocke's Bank! Please register an one-time use account below." << endl;
	char regAccName, acc;
	int regPwd;
	int pwd = 65782;
	cout << "Please register an account name: ";
	cin >> regAccName;
	cout << "Here is a one-time use password to your account: " << pwd << endl;
	acc = regAccName;

	//login
	cout << endl;
	cout << "Please login with your one-time-use account below:" << endl;
	cout << "Account Name: ";
	cin >> regAccName;
	cout << "Password: ";
	cin >> regPwd;
	if (regAccName == acc && regPwd == pwd)
	{
		cout << "Successfully logged in!" << endl;
	}
	else if (regAccName != acc)
	{
		cout << "Incorrect account name." << endl;
	}
	else if (regPwd != pwd)
	{
		cout << "Incorrect password." << endl;
	}
	else
	{
		cout << "Something gone wrong. Please restart the program." << endl;
	}
	return 0;
}


I tried to only run the "register" part in the code (by making the "login" code into comments), and the same problem occured. The thing that's not working as it should, is that the code doesn't allow me to enter the password etc, it's like it doesn't read the cin. I also tried renaming the variables of the cin (so it doesn't "c-in" the same variable name twice, but no positive results were given.

I simply can't find an issue in the code either.
Any help is appreciated!

Thanks in advance!
Sincerely,
Jocke
char regAccName, acc;

cin will only grab one character from "jocke" making the name and password equaling to 'o' and 'c'. Make your code char* or use std::string.

Give it a try.
I tried using string instead of char and now it works!

Thank you very very much! :)
You're very welcome I'm happy to help :)
Topic archived. No new replies allowed.