I know very little about C++. I would like to use an if command in this way:
Ask user to enter a word
if word is "something!"
cout "bleah!"
else
if word is "other!"
cout "miscellaneous!"
I know very little about C++. I would like to use an if command in this way:
Ask user to enter a word
if word is "something!"
cout "bleah!"
else
if word is "other!"
cout "miscellaneous!"
if and else dont work with character arrays which is what im assuming what you mean by a "string". you could use std::string, but since youve just started, i dont suggest it. you could use strcmp()...
You can use either if else statements or witch statement.
I think this is good code.Code:if( word == " word1") cout<< res1; else if( word == " word2") cout<< res2; else cout<< res3; //OR switch word { word1: {cout<< res1; break;} word2: {cout<< res2; break;} word3: {cout<< res3; break;} }
C++
The best
please note that if u have more than one line of code following your if statement these lines must be enclosed in matching {}
example:
if(word==word1)
{cout<<"abc";
cout<<"xyz";
}
else
abc
if u dont put the {} your compiler will only read the line immediately following the if statement.