it keeps saying theres an error on line 17,

it says:
"no match for 'operator!=' in 'a != password'"

#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
    string password;
    cout << "Type in a password: ";
    cin >> password;
    
    char a;
    a = 'A';
    
    cout << a;
    if (a != password)
    {
          cout << "\tFailed\n";
          a = 'B';
    }
    else
    {
        cout << "\tSuccess!!!";
        
system ("PAUSE");
return 0;
}     


  
system ("PAUSE");
return 0;
}
Member Avatar for iamthwee

try changing

char a;
a = 'A';

to:
string a;
a = "A";

and do a

#include <string> at the top

it keeps saying theres an error on line 17,

it says:
"no match for 'operator!=' in 'a != password'"

Your trying to compare a char with a string, there is no operator for that. Either use a char to store the password, or (much better plan) use a string to store the A variable.

string a;

Dear actually you compare a whole string with a single character which is a bad programming pratice. you just declare password as a char ( char password ) . Now it compares.

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main() {
    // your mistake you write string password.
    char password;
    cout << "Type in a password: ";
    cin >> password;
    char a;
    a = 'A';
    cout << a;
    if (password != a) {
          cout << "\tFailed\n";
          a = 'B';
    } else {
        cout << "\tSuccess!!!";
    }
system ("PAUSE");
return 0;
}

Now compile it it is erorr free.
I hope you enjoy it.

you just declare password as a char ( char password ) .
Now compile it it is erorr free.
I hope you enjoy it.

that is assuming their password is something like 'b' or '7' (I hope it's not) and just because something compiles doesn't mean it works ;)

this compiles:

#include <iostream>
#include <vector>
using namespace std;

int main()
{
     vector<int> values;
     values.push_back(1);

     for(int x = 0; x < 10000; x++)
          cout << values[x] << endl; //segfault anybody?

     return 0;
}

OP: I'm with Darth, change a to a string

that is assuming their password is something like 'b' or '7' (I hope it's not) and just because something compiles doesn't mean it works ;)

this compiles:

#include <iostream>
#include <vector>
using namespace std;

int main()
{
     vector<int> values;
     values.push_back(1);

     for(int x = 0; x < 10000; x++)
          cout << values[x] << endl; //segfault anybody?

     return 0;
}

OP: I'm with Darth, change a to a string

Dear I cannot understand what you are saying.
Please clear it then I solve your problem. I already solve your above problem.

Thanks

Dear I cannot understand what you are saying.
Please clear it then I solve your problem. I already solve your above problem.
Thanks

There was no problem, Jesseb07 was simply agreeing with my statement and posting a full code for it.

Dear I cannot understand what you are saying.
Please clear it then I solve your problem. I already solve your above problem.

Thanks

Alright, mirfan00 you aren't paying attention. A char holds 1 character, such as the letter 'A'. If you are trying to program something with a password how smart would it be to only allow a 1 character password?

You created a logic issue, it makes no sense to do that.

The above user you weren't able to understand was telling you that even though your code compiles, doesn't mean it is the right code to use.

Meaning, just because you can compare a char to a char, doesn't mean you should be using a char at all.

commented: Agreed +1

A password program which is only accepting passwords which consist out of one character is not a bad coding practice, but it's a bad security practice :)

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.