Answer the question
In order to leave comments, you need to log in
How to make answer options (Solved)?
How to make response options with if and else? Type
Console.WriteLine ("1 or 2");
bool a = true
bool b = false
if (a){
Console.WriteLine ("Result 1");
}
else (b){
Console.WriteLine ("Result 2");
}
Console.ReadLine;
Answer the question
In order to leave comments, you need to log in
bool isOk;
if (isOk == true)
{
std::cout << "result1";
}
else
{
std::cout << "result2";
}
size_t answer;
if (answer == 1)
{
std::cout << "result1";
}
else if(answer == 2)
{
std::cout << "result2";
}
In fact, it is not clear how the code should work, what you want to get from it.
Re-read the C# tutorial where the if statement is described. You are not using the else construct in it correctly.
if (a){
Console.WriteLine ("Result 1");
} else if(b){
Console.WriteLine ("Result 2");
}
You can do without bool in this case, instead, compare the entered and expected text.
Comparison example:
// Get the entered text by writing it to the variable text
string text = Console.ReadLine();
// Compare: if 1 is entered, then output "result 1"
if (text == "1")
Console.WriteLine("result 1");
// If the text is not equal to 1, but is equal to 2, then output result 2
else if (text == "2")
Console.WriteLine("result 2");
// If the text is neither 1 nor 2, then output something else
else
Console.WriteLine("Method not found");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question