What am i doing wrong?

I need to make a simple registration form like facebook. why won't my program work properly? the response isnt working and when i input more than one letter in the registration it doesnt work.

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
#include <iostream>
#include <conio.h>
using namespace std;
int main(){
char response, firstname, lastname, email, password, birthday, gender, email2, password2;
cout<<"Welcome To Facebook - Log in, Sign Up, and Learn More\n"
"Do you have an existing account?(y/n)";
cin>>response;
if (response == 'Y' && response == 'y')
{cout<<"Log In:\n"
"Email or Phone:";
cin>>email2;
cout<<"Password:";
cin>>password2;}
else if (response == 'N' && response == 'n')
cout<<"Sign Up\n It's free and always will be.\n";
cout<<"First name?";
cin>>firstname;
cout<<"Last name?";
cin>>lastname;
cout<<"Email:";
cin>>email;
cout<<"Re-enter email:";
cin>>email;
cout<<"Password:";
cin>>password;
cout<<"Birthday?";
cin>>birthday;
cout<<"Female(f) or Male(m)?";
cin>>gender;
cout<<"Congratulations on creating your new account! Here is your profile information:";
cout<<"\nFirst Name:"<<firstname;
cout<<"\nLast Name:"<<lastname;
cout<<"\nEmail:"<<email;
cout<<"\nPassword:"<<password;
cout<<"\nBirthday:"<<birthday;
cout<<"\nGender:"<<gender;
  system("PAUSE");
  return 0;
  }

edit: the response meaning the yes or no questions is not working, it just proceeds to "First Name?". even if i input y it still prints "first name".
Last edited on
Most of your variables sould be std::string type instead of char type. char stores a single character whereas a string is a string of multiple characters.

Moreover, for future if you specify exactly 'what doesn't work', it'll be a lot easier. In other words, you should clearly specify the error that you are getting or the unexpected output that you are getting.
Yeah all the variables except response (and maybe gender) need to be string variables.

Also,

if (response == 'Y' && response == 'y')

Needs to be:

if (response == 'Y' || response == 'y')

And, you need brackets around the statements below the else if

This works, but you might want to make it check whether user enters something other than y or n for response...

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
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
	char response;
	string firstname, lastname, email, password, birthday, gender, email2, password2;
	
	cout<<"Welcome To Facebook - Log in, Sign Up, and Learn More\n"
	"Do you have an existing account?(y/n)";
	cin>>response;
	
	if (response == 'Y' || response == 'y') // changed && to ||
	{
		cout<<"Log In:\n"
		"Email or Phone:";
		cin>>email2;
		cout<<"Password:";
		cin>>password2;
	}
	else if (response == 'N' || response == 'n') // changed && to ||
	{ // added brackets for this block of statements
		cout<<"Sign Up\n It's free and always will be.\n";
		cout<<"First name?";
		cin>>firstname;
		cout<<"Last name?";
		cin>>lastname;
		cout<<"Email:";
		cin>>email;
		cout<<"Re-enter email:";
		cin>>email;
		cout<<"Password:";
		cin>>password;
		cout<<"Birthday?";
		cin>>birthday;
		cout<<"Female(f) or Male(m)?";
		cin>>gender;
		cout<<"Congratulations on creating your new account! Here is your profile information:";
		cout<<"\nFirst Name:"<<firstname;
		cout<<"\nLast Name:"<<lastname;
		cout<<"\nEmail:"<<email;
		cout<<"\nPassword:"<<password;
		cout<<"\nBirthday:"<<birthday;
		cout<<"\nGender:"<<gender;
	}
	  system("PAUSE");
	  return 0;
}
Last edited on
Thank you it works now!
Topic archived. No new replies allowed.