Im a complete begginer in c++ so im having diffuculty with this problem.
This is my problem.
1. Status of boy ang girl should be less than single.
If i declare it like this
1 2 3 4 5 6 7 8 9 10
int main ()
{
int sg;
cin>>sg;
cout<<"Please enter relationship status:"<<sg<<;
If (!(sg==single))
cout<<"Married are out"<<endl;
BUT if the user puts other than MARRIED im putting another statement there. My question is if the IF statement i used is correct? And what i should replace/add if the user adds another answer other than single?
I don't know what exactly your problem.
There are some mistakes in your program:
1:IF should be written by small letters
2:you can't enter a string when "sg" is defined as an integer
Also I wrote a code you can't take a look at it and tell me if it works true.
int main()
{
int a;
cout<<"Enter a number(Married:1 Single:2):";
cin>>a;
if (a==1)
cout<<"You are married.";
else if (a==2)
cout<<"You are single.";
else
cout<<"Error";
return 0;
}
My question is if the IF statement i used is correct?
No. In this case, the compiler is going to treat single as a variable, but it hasn't been declared, so you'll get an error.(Use double quotes for single. As in "single")
2. sg is of type int, so it cannot accept strings.(Change the type to std::string)
3. cout is used for output purposes, and cin is for input.
1 2
cout<<"Please enter relationship status: ";
cin>>sg;
BUT if the user puts other than MARRIED im putting another statement there.
You can use the std::to_lower() function (the name might not be correct) if(std::to_lower(sg)=="single") .....
And what i should replace/add if the user adds another answer other than single?