Hey, im making a code to ask a user to type in a username and password to continue and for the console to say "thanks" and i need help. Heres my "Unsuccessful" Code:

#include <iostream>

using namespace std;

int main(){
    int a, b;
    a = 159876;
    b = 43812385;
    int c;
    int d;
    
    cout << "Please Enter your Username:";
    cin >> c;
    
    cout << "Please Enter a Password:";
    cin >> d;
    
    if (c != b && d != a){
          cout << "Incorrect Username/Password Combintation \n";
          }
    if (c == b && d = a){
          cout << "What would you like to do";
          
          }
          
          system("Pause");
}

#1) Use better variables: PswdIn, Pswd, Name, NameIn would be much better.

#2) Display the values before the IF statements to make sure they are the same.

What do u mean write the values before the if statement?
And thanks for helping

You have a logic error in your code. Remember your logic tables ab = a'+b' meaning. Also you switched the terms

if (c != b && d != a){
          cout << "Incorrect Username/Password Combintation \n";
          }

should be

if (c != a || d != b){
          cout << "Incorrect Username/Password Combintation \n";
          }

Think about it like this. If you asked for both of them not to be equal to the proper values, then if the username is correct but the password is incorrect the program would continue, but if you say that when one is true (c!=a or d!=b) then the whole statement is true it will work.

Also you forgot an = sign:

if (c == b && d = a){
          cout << "What would you like to do";

should be

if (c == b && d == a){
          cout << "What would you like to do";

You test 2 conditions (lines 18 and 21). One of them is supposed to filter out incorrect attempts. Another is supposed to accept correct ones. Logically, they should be mutual negations. The way they are written they are not. Hint.
Besides, why do you want to test both?

You test 2 conditions (lines 18 and 21). One of them is supposed to filter out incorrect attempts. Another is supposed to accept correct ones. Logically, they should be mutual negations. The way they are written they are not. Hint.
Besides, why do you want to test both?

Well i want to test both so that its easier to understand, im a html coder and thats the way ive been taught in HTML, so i just incorporated it into C++,

And thanks everyone for helping me. Im only new to C++ and your replies have helped heaps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.