Sep 24, 2016 at 6:33pm UTC
What do you mean?
explain your problem clearly.
Last edited on Sep 24, 2016 at 6:37pm UTC
Sep 24, 2016 at 6:36pm UTC
can you do something like
if a variable is not equal to a number{
do something
}
?
thx again.
Sep 24, 2016 at 6:43pm UTC
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.
Sep 24, 2016 at 6:44pm UTC
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
Sep 24, 2016 at 6:52pm UTC
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.
Sep 24, 2016 at 6:53pm UTC
!==
is wrong.
!=
is correct.
try again
Sep 24, 2016 at 6:55pm UTC
!= don't work.
try again.
IT JUST DON"T WORK
Sep 24, 2016 at 6:55pm UTC
thx for the advice though, but i already learned cpp. So i need to learn c next?
Last edited on Sep 24, 2016 at 6:58pm UTC
Sep 24, 2016 at 7:00pm UTC
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 Sep 24, 2016 at 7:01pm UTC
Sep 24, 2016 at 7:03pm UTC
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?
Sep 24, 2016 at 7:05pm UTC
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...
Sep 24, 2016 at 7:09pm UTC
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 Sep 24, 2016 at 7:09pm UTC
Sep 24, 2016 at 7:13pm UTC
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 Sep 24, 2016 at 7:15pm UTC
Sep 24, 2016 at 7:21pm UTC
I use windows and Code::Blocks IDE.
if you use another operating system or another IDE, I have no idea.
Sep 24, 2016 at 7:31pm UTC
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