Advertisement
Guest User

SamsMultiplicationC#

a guest
Jun 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.63 KB | None | 0 0
  1. /*
  2.  * Created by SharpDevelop.
  3.  * User: 5156395
  4.  * Date: 19/06/2017
  5.  * Time: 10:57
  6.  *
  7.  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8.  */
  9. using System;
  10.  
  11. namespace Multiplication
  12. {
  13.     class Program
  14.     {
  15.         public static void Main(string[] args)
  16.         {
  17.             Console.WriteLine ("Hello and welcome to the multiplication program. When you are ready type start or help if you need help.");
  18.            
  19.             string help = Console.ReadLine(); //This allows the program to recognise if the user has typed help or not
  20.            
  21.             if (help == "help" || help == "Help") //This runs the help if loop if the user has typed help
  22.             {
  23.                 Console.WriteLine ("You will be asked 10 multiplication questions where the answer will be no higher than 100. To answer them type in what you believe the answer to be. After the test is over you will be told how many you got correct. Type start when ready to begin");
  24.             }
  25.  
  26.            
  27.             while(true) //This is the while loop for the questions
  28.             {
  29.                 string UserInput = Console.ReadLine(); //This allows the program to recognise if the user has typed start or not
  30.                 int Correct = 0;
  31.                
  32.                 if(UserInput == "Start" || UserInput == "start") //This runs the multiplication code if the user has typed start
  33.                 {
  34.                     int Min = 1; //These are the min and max numbers for the random generator
  35.                     int Max = 10;
  36.                    
  37.                     Random Rnd = new Random(); // This is the random number generator that creats all 20 random numbers
  38.                    
  39.                     int Number1 = Rnd.Next(Min,Max);
  40.                     int Number2 = Rnd.Next(Min,Max);
  41.                     int Number3 = Rnd.Next(Min,Max);
  42.                     int Number4 = Rnd.Next(Min,Max);
  43.                     int Number5 = Rnd.Next(Min,Max);
  44.                     int Number6 = Rnd.Next(Min,Max);
  45.                     int Number7 = Rnd.Next(Min,Max);
  46.                     int Number8 = Rnd.Next(Min,Max);
  47.                     int Number9 = Rnd.Next(Min,Max);
  48.                     int Number10 = Rnd.Next(Min,Max);
  49.                     int Number11 = Rnd.Next(Min,Max);
  50.                     int Number12 = Rnd.Next(Min,Max);
  51.                     int Number13 = Rnd.Next(Min,Max);
  52.                     int Number14 = Rnd.Next(Min,Max);
  53.                     int Number15 = Rnd.Next(Min,Max);
  54.                     int Number16 = Rnd.Next(Min,Max);
  55.                     int Number17 = Rnd.Next(Min,Max);
  56.                     int Number18 = Rnd.Next(Min,Max);
  57.                     int Number19 = Rnd.Next(Min,Max);
  58.                     int Number20 = Rnd.Next(Min,Max);
  59.                    
  60.                     //Question 1
  61.                     Console.WriteLine("What is " +Number1+ " X " +Number2+ "?"); //This lets the user see the question
  62.                     String A1 = Console.ReadLine();
  63.                     int A1int = Convert.ToInt32(A1); //This converts their answer from a string to a int
  64.                     if (A1int == Number1*Number2) //This checks to see if the user got the answer right or not
  65.                        
  66.                     {
  67.                         Console.WriteLine("You are correct"); //This is what happens if they did
  68.                         Correct++;
  69.                     }
  70.                    
  71.                     else
  72.                        
  73.                     {
  74.                         Console.WriteLine("Better luck next time"); //This is what happens if they didnt
  75.                     }
  76.                    
  77.                     //Question 2
  78.                     Console.WriteLine("What is " +Number3+ " X " +Number4+ "?");
  79.                     String A2 = Console.ReadLine();
  80.                     int A2int = Convert.ToInt32(A2);
  81.                     if (A2int == Number3*Number4)
  82.                        
  83.                     {
  84.                         Console.WriteLine("You are correct");
  85.                         Correct++;
  86.                     }
  87.                    
  88.                     else
  89.                        
  90.                     {
  91.                         Console.WriteLine("Better luck next time");
  92.                     }
  93.                    
  94.                     //Question 3
  95.                     Console.WriteLine("What is " +Number5+ " X " +Number6+ "?");
  96.                     String A3 = Console.ReadLine();
  97.                     int A3int = Convert.ToInt32(A3);
  98.                     if (A3int == Number5*Number6)
  99.                        
  100.                     {
  101.                         Console.WriteLine("You are correct");
  102.                         Correct++;
  103.                     }
  104.                    
  105.                     else
  106.                        
  107.                     {
  108.                         Console.WriteLine("Better luck next time");
  109.                     }
  110.                    
  111.                     //Question 4
  112.                     Console.WriteLine("What is " +Number7+ " X " +Number8+ "?");
  113.                     String A4 = Console.ReadLine();
  114.                     int A4int = Convert.ToInt32(A4);
  115.                     if (A4int == Number7*Number8)
  116.                        
  117.                     {
  118.                         Console.WriteLine("You are correct");
  119.                         Correct++;
  120.                     }
  121.                    
  122.                     else
  123.                        
  124.                     {
  125.                         Console.WriteLine("Better luck next time");
  126.                     }
  127.                    
  128.                     //Question 5
  129.                     Console.WriteLine("What is " +Number9+ " X " +Number10+ "?");
  130.                     String A5 = Console.ReadLine();
  131.                     int A5int = Convert.ToInt32(A5);
  132.                     if (A5int == Number9*Number10)
  133.                        
  134.                     {
  135.                         Console.WriteLine("You are correct");
  136.                         Correct++;
  137.                     }
  138.                    
  139.                     else
  140.                        
  141.                     {
  142.                         Console.WriteLine("Better luck next time");
  143.                     }
  144.                    
  145.                     //Question 6
  146.                     Console.WriteLine("What is " +Number11+ " X " +Number12+ "?");
  147.                     String A6 = Console.ReadLine();
  148.                     int A6int = Convert.ToInt32(A6);
  149.                     if (A6int == Number11*Number12)
  150.                        
  151.                     {
  152.                         Console.WriteLine("You are correct");
  153.                         Correct++;
  154.                     }
  155.                    
  156.                     else
  157.                        
  158.                     {
  159.                         Console.WriteLine("Better luck next time");
  160.                     }
  161.                    
  162.                     //Question 7
  163.                     Console.WriteLine("What is " +Number13+ " X " +Number14+ "?");
  164.                     String A7 = Console.ReadLine();
  165.                     int A7int = Convert.ToInt32(A7);
  166.                     if (A7int == Number13*Number14)
  167.                        
  168.                     {
  169.                         Console.WriteLine("You are correct");
  170.                         Correct++;
  171.                     }
  172.                    
  173.                     else
  174.                        
  175.                     {
  176.                         Console.WriteLine("Better luck next time");
  177.                     }
  178.                    
  179.                     //Question 8
  180.                     Console.WriteLine("What is " +Number15+ " X " +Number16+ "?");
  181.                     String A8 = Console.ReadLine();
  182.                     int A8int = Convert.ToInt32(A8);
  183.                     if (A8int == Number15*Number16)
  184.                        
  185.                     {
  186.                         Console.WriteLine("You are correct");
  187.                         Correct++;
  188.                     }
  189.                    
  190.                     else
  191.                        
  192.                     {
  193.                         Console.WriteLine("Better luck next time");
  194.                     }
  195.                    
  196.                     //Question 9
  197.                     Console.WriteLine("What is " +Number17+ " X " +Number18+ "?");
  198.                     String A9 = Console.ReadLine();
  199.                     int A9int = Convert.ToInt32(A9);
  200.                     if (A9int == Number17*Number18)
  201.                        
  202.                     {
  203.                         Console.WriteLine("You are correct");
  204.                         Correct++;
  205.                     }
  206.                    
  207.                     else
  208.                        
  209.                     {
  210.                         Console.WriteLine("Better luck next time");
  211.                     }
  212.                    
  213.                     //Question 10
  214.                     Console.WriteLine("What is " +Number19+ " X " +Number20+ "?");
  215.                     String A10 = Console.ReadLine();
  216.                     int A10int = Convert.ToInt32(A10);
  217.                     if (A10int == Number19*Number20)
  218.                        
  219.                     {
  220.                         Console.WriteLine("You are correct");
  221.                         Correct++;
  222.                     }
  223.                    
  224.                     else
  225.                        
  226.                     {
  227.                         Console.WriteLine("Better luck next time");
  228.                     }
  229.                    
  230.                    
  231.                 }
  232.                
  233.                 else
  234.                 {
  235.                     continue;
  236.                 }
  237.                
  238.                 Console.WriteLine("Congratulations you got " +Correct+ " out of 10 correct"); //This tells the user how many questions they got right
  239.                 Console.WriteLine("Press any key to exit ...");
  240.                 Console.ReadKey(true); // This stops the program from exiting straight away
  241.                
  242.                
  243.                 break;
  244.             }
  245.                
  246.                
  247.         }
  248.     }
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement