Loops, can you guys check this out

I need some help on this, apparently, if I run this, and put the right password and username, it still goes to the else statement. I can't figure out how to make the if statement codes appear and work.

here are my codes

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
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdio.h>
#define g gotoxy
main()
{
clrscr();
int w,x,y,z;
char un[50],pass[50],option,option2;

do
{
clrscr();
g(25,6); cout<<"Welcome to MATRIX WORLD!";
g(32,8); cout<<"Username:\n";
g(32,10); cout<<"Password:\n";
g(32,9); gets(un);
g(32,11); gets(pass);

	if((un=="Mizore") && (pass=="R+V"))
	do
	{
		clrscr();
		g(30,6); cout<<"Choose transaction:";
		g(27,8); cout<<"[1] - Ascending numbers";
		g(34,9); cout<<"(using for loop)";
		g(27,10); cout<<"[2] - Descending numbers";
		g(34,11); cout<<"(using while loop)";
		g(27,12); cout<<"[3] - Programmer's Profile";
		g(36,7); cin>>x;
		{
		switch(x)
		{
			case 1:

				clrscr();
				cout<<"Enter a number: "; cin>>y;
				cout<<"\nEnter ending number: "; cin>>z;
				cout<<"\nAscending numbers are\n";
				for(w=y; w<=z; w++)
					{
					cout<<w<<"\n";
					delay(500);
					}
				break;

			case 2:

				clrscr();
				cout<<"Enter a number: "; cin>>y;
				cout<<"\nEnter ending number: "; cin>>z;
				cout<<"\nDescending numbers are\n";
				for(w=y; w>=z; w--)
					{
					cout<<w<<"\n";
					delay(500);
					}
				break;

			case 3:

				clrscr();
				g(30,5); cout<<"PROGRAMMER";
				g(20,7); cout<<"LOLOLOLOLOLOLOL";
				g(25,9); cout<<"COPYRIGHT MARCH 2013";
				break;

			default:

				clrscr();
				cout<<"Your input was invalid\n";
				cout<<"Do you want to choose again?Y for yes\n";
				cin>>option2;
				break;

		}
		}
	}
	while(option2=='Y'||option2=='y');
	else
	{
		clrscr();
		g(28,8); cout<<"Sorry you have entered incorrect";
		g(32,10); cout<<"Username and Password!";
		g(23,12); cout<<"Press Y/y to go back to the log in screen";
		g(35,14); cin>>option;
	}
}
while(option=='Y'||option=='y');
clrscr();
g(28,10); cout<<"Thank you for using my program!";



getch();
return 0;
}
Last edited on
cuz what you doing is wrong!!
if you declare them like this

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
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string> // <<<<<< string
using namespace std;

#define g gotoxy

 int main()
 {
 int w,x,y,z;
 string un,pass; // <<< as strings
char option,option2;

 do
{
clrscr();
g(25,6); cout<<"Welcome to MATRIX WORLD!";
g(32,8); cout<<"Username:\n";
g(32,10); cout<<"Password:\n";
cin >>un;
cin >> pass;
...
...
...


OR
you can use strcmp with them without string
Last edited on
First, you should use code tags:
[code]Your code here[/code]

The reason is that you can't use == to compare character arrays. As suggested, use strings instead.

Other then that, you should probably not use conio.h as it is non-standard and doesn't exist (or does different stuff) on different platforms. This means don't use gotoxy or clrscr.

Also:
if((un=="Mizore") && (pass=="R+V"))
Is this a reference to Rosario + Vampire?
@firdraco
Rosario+Vampire? Yes.
plus, we need to use clrscr() since we have a format we should follow, as well as gotoxy is need in that.

@joneele
I'm still a student, sorry.
How do I use strcmp?
Last edited on
I'm still a student, sorry.

Even students like using manual pages. On UNIX based system have a look at
man strcmp.

How do I use strcmp?


int strcmp(const char *arg1, const char *arg2)

Returns
0 arg1 and arg2 are same
<0 arg1 is lexically less than arg2
>0 arg1 is lexically greater than arg2
Last edited on
@tcs
thanks for the codes, although, I always get a misplaced else in this part

1
2
3
4
5
6
7
8
else
	{
		clrscr();
		g(28,8); cout<<"Sorry you have entered incorrect";
		g(32,10); cout<<"Username and Password!";
		g(23,12); cout<<"Press Y/y to go back to the log in screen";
		g(35,14); cin>>option;
	}


any advice? I still have time till tuesday to fix this project of mine :)

P.S. My professor would be mad again if I use another set of codes, can you guys help me on the codes up there :(
Last edited on
Topic archived. No new replies allowed.