Password Program

I am trying to create a simple password program in which the Password is already loaded into the program and the user enters a variable which The program will then Answer with Either Correct or Incorrect. I need to Find out why it wont 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
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;

void hint(char usrv)
{

if (usrv=18)
	cout<<"CORRECT"<<endl;
else 
	cout<<"INCORRECT"<<endl;
}

int main()
{
int usrv;
cout<<"LOGIN:"<<endl;
	cin>>usrv;
hint(usrv);
system ("PAUSE");
return 0;
}
in line 9, replace:
if (usrv=18)
with
if (usrv==18)

= is the assignment operator, it means you are setting usrv to 18 which is a strange thing to do in an if statement (but possible).

== is the comparison operator, it will return true if the two arguments are equal.
haha, easy fix total forgot that i have to use ==.
Topic archived. No new replies allowed.