combining random generators and switch statements inside of methods

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Good evening everyone. I am trying to create a practice multiplication app for an education based client (elementary students). The issue that I am having is my switch statements are said to be unreadable. I am trying to generate a different
response whenever the student enters the correct or incorrect answer. I also want to create it like a quiz with a restriction of 10 questions at a time. I want to do this so that I can add up the correct answers and display a percentage of correct
answers.
Heres the code
namespace multiplication<br/>
{<br/>
class Program<br/>
{<br/>
static void Main(string[] args)<br/>
{<br/>
//declare variables<br/>
int attempt;<br/>
int mathproblem;<br/>
int ran1 = Random1();<br/>
int ran2 = Random2();<br/>
//calculation for the math problem<br/>
mathproblem = ran1 * ran2;<br/>
//prompt the user to enter the answer to the math problem <br/>
Console.WriteLine("What is {0} times {1} ? -1 to quit:", ran1, ran2);<br/>
attempt = Convert.ToInt32(Console.ReadLine());<br/>
//start the loop <br/>
while (attempt != -1)<br/>
{//if the answer is incorrect, this loop will start<br/>
while (attempt != mathproblem)<br/>
{<br/>
Console.WriteLine("No, Please try again.:");<br/>
Console.WriteLine("What is {0} times {1} ? -1 to quit:", ran1, ran2);<br/>
attempt = Convert.ToInt32(Console.ReadLine());<br/>
}<br/>
//if the answer is correct, this loop will start<br/>
Console.WriteLine("You guessed correctly!:");<br/>
//resetting the values to start everything over again (different math equation will start)<br/>
attempt = 0;<br/>
mathproblem = 0;<br/>
ran1 = Random1();<br/>
ran2 = Random2();<br/>
mathproblem = ran1 * ran2<br/>
<br/>
;<br/>
Console.WriteLine("What is {0} times {1} ? -1 to quit:", ran1, ran2);<br/>
attempt = Convert.ToInt32(Console.ReadLine());<br/>
}<br/>
Console.ReadLine();<br/>
}<br/>
//first random number<br/>
public static int Random1()<br/>
{<br/>
Random RandomInt = new Random();<br/>
int number1 = RandomInt.Next(1, 10);<br/>
return number1;<br/>
}<br/>
//second random number generated<br/>
public static int Random2()<br/>
{<br/>
Random RandomInt = new Random();<br/>
int number2 = RandomInt.Next(2, 11);<br/>
return number2;<br/>
}<br/>
//correct responses<br/>
public static int correct()<br/>
{<br/>
Random RandomInt = new Random();<br/>
int number3 = RandomInt.Next(2, 4);<br/>
return number3;<br/>
switch (number3)<br/>
{<br/>
case 1:<br/>
Console.WriteLine("Excellent!");<br/>
break;<br/>
case 2:<br/>
Console.WriteLine("Very Good!");<br/>
break;<br/>
case 3:<br/>
Console.WriteLine("Great Job!");<br/>
break;<br/>
case 4:<br/>
Console.WriteLine("Keep up the good work!");<br/>
<br/>
}<br/>
}<br/>
//incorrect responses<br/>
public static int incorrect()<br/>
{<br/>
Random RandomInt = new Random();<br/>
int number4 = RandomInt.Next(2, 4);<br/>
return number4;<br/>
switch (number4)<br/>
{<br/>
case 1:<br/>
Console.WriteLine("Please try again");<br/>
break;<br/>
case 2:<br/>
Console.WriteLine("Dont Give up");<br/>
break;<br/>
case 3:<br/>
Console.WriteLine("Try it again");<br/>
break;<br/>
case 4:<br/>
Console.WriteLine("No, Please answer it again");<br/>
}<br/>
}<br/>
}<br/>
}

View the full article
 
Back
Top