Weird...

Pages: 12
I felt like my c++ knowledge is leaving me... can you do something like this?

1
2
3
 if (something !== 5||2||6){
balah blah blah
}


i don't know if you can do this... if you can, plz help me

thx.
What do you mean?
explain your problem clearly.
Last edited on
can you do something like

if a variable is not equal to a number{
do something
}

?
thx again.
Maybe you mean this:

1
2
3
4
5
if(something!=5 || something!=2 || something!=6){
.
.
.
}
for checking equality of two numbers, you should use ==.
for checking inequality, you should use !=

note that = is for assignment and == is for checking equality.
yeah something like that but it doesn't work.

if i do something !==5 it gives me an error...
expected primary expression before '=' token or something like that...

thx
Dear WheatFieldOnFire,
for learning C++, it is better to learn C first and when you become advanced in C language, you can easily learn C++ without any serious struggles.
It doesn't mean that anybody can't learn C++ until he/she learn C, I mean that it's easier and better.
However, I offer you to stop writing programs and first try to learn the language you want.
!== is wrong.
!= is correct.

try again
!= don't work.

try again.

IT JUST DON"T WORK
thx for the advice though, but i already learned cpp. So i need to learn c next?
Last edited on
send the code you have write or try mine:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

using namespace std;

int main(){
int firstNumber=10, secondNumber=20;

if(firstNumber != secondNumber){
cout<< "10 is not equal to 20" ;
}
if(firstNumber == secondNumber){
cout<< "10 is equal to 20" ;
}

return 0;
}
Last edited on
wait i see your point... it worked on cpp.sh but didn't work on my IDE or something... can you do the same (!=) with strings?
like my program is asking for a string and i want to see if the user entered a valid string answer like the options i gave them...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>

using namespace std;

int main(){
string S1("My first string");
string S2("My second string");

if(S1 != S2){
cout<<S1<<'\n'<<"is not equal to "<<'\n'<<S2 ;
}

return 0;
}
Last edited on
but like i want to ask for the string from user and then "compare" it... it didn't work...

like

cin string;

if string==something
{...}else if string==something2
{...}else if string!=something2||something //this part
{...}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>

using namespace std;

int main(){
string password("My password");
string userEntered;

cout<<"Please Enter your password: ";
cin>>userEntered;

if(userEntered == password){
    cout<<"Correct password";
}
if(userEntered != password){
    cout<<"Wrong password";
}

return 0;
}
I use windows and Code::Blocks IDE.
if you use another operating system or another IDE, I have no idea.
we've the same one. but i used else if statements instead of just if... so i guess that is why it didn't work.

thx
u cant do this: if(something !== 5||2||6)
u have to do like this
 
if(something !=2 || something !=5 || something != 6)

for the sting comparison. u have to do either one.
1
2
3
4
5
cin >> sting;
if( string == "something") // put " " to a string that u didn't declare
or 
string b="something";
if(sting == b)
Pages: 12