samedi 26 octobre 2019

Is there a more efficient way to make a quiz and have two different outcomes based on if the answers are mostly yes/no?

This is a quiz that determines if the user likes eggs or not based on if at least 50% of their answers are yes or true.

Console.WriteLine ("This quiz will find out if you like eggs");

Console.WriteLine ("Do you like ketchup? (yes/no)");
string quiz1 = (Console.ReadLine());
bool quiza1 = (quiz1.Contains("yes"));

Console.WriteLine ("Do you like bread? (yes/no)");
string quiz2 = (Console.ReadLine());
bool quiza2 = (quiz2.Contains("yes"));

Console.WriteLine ("Do you like to read? (yes/no)");
string quiz3 = (Console.ReadLine());
bool quiza3 = (quiz3.Contains("yes"));

Console.WriteLine ("Do you like soda? (yes/no)");
string quiz4 = (Console.ReadLine());
bool quiza4 = (quiz4.Contains("yes"));

if (quiza1 == true && quiza2 == true || quiza1 == true && quiza3 == true || quiza1 == true && quiza4 == true || quiza2 == true && quiza3 == true || quiza2 == true && quiza4 == true || quiza3 == true && quiza4 == true)
{
    Console.WriteLine ("You probably like eggs");
}
else
{
    Console.WriteLine ("I don't think you like eggs");
}

I'm specifically looking to replace the if statement with something more compact.

Aucun commentaire:

Enregistrer un commentaire