Advertisement
Guest User

Matrix School Assignment

a guest
Oct 17th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string hairColour = string.Empty;
  14.             string jobType = string.Empty;
  15.             string raceType = string.Empty;
  16.             int intRace = 0;
  17.             int intHair = 0;
  18.             int intJob = 0;
  19.             bool validUserInput1 = false;
  20.             bool validUserInput2 = false;
  21.             bool validUserInput3 = false;
  22.  
  23.             while (validUserInput1 == false)
  24.             {
  25.                 try
  26.                 {
  27.                     Console.WriteLine("Please choose a race. 1 = Human. 2 = Dwarf. 3 = Elf.");
  28.                     intRace = int.Parse(Console.ReadLine()); //try to parse string as int variable
  29.                 }
  30.                 catch (Exception) { } //catch invalid input exception
  31.  
  32.                 if ((intRace >= 1) && (intRace <= 3)) //ensure entered int is >= 1 but <=3
  33.                 { validUserInput1 = true; }
  34.                 else { Console.WriteLine("Invalid Input.  "); }
  35.             }
  36.  
  37.             Console.WriteLine("You have selected " + intRace);
  38.  
  39.             while (validUserInput2 == false)
  40.             {
  41.                 try
  42.                 {
  43.                     Console.WriteLine("Please choose your hair colour. 1 = Brown. 2 = Blonde. 3 = Red.");
  44.                     intHair = int.Parse(Console.ReadLine()); //try to parse string as int variable
  45.                 }
  46.                 catch (Exception) { } //catch invalid input exception
  47.  
  48.                 if ((intHair >= 1) && (intHair <= 3)) //ensure entered int is >= 1 but <=3
  49.                 { validUserInput2 = true; }
  50.                 else { Console.WriteLine("Invalid Input.  "); }
  51.             }
  52.  
  53.             Console.WriteLine("You have selected " + intHair);
  54.  
  55.  
  56.             while (validUserInput3 == false)
  57.             {
  58.                 try
  59.                 {
  60.                     Console.WriteLine("Please choose your job. 1 = Warrior. 2 = Mage. 3 = Thief.");
  61.                     intJob = int.Parse(Console.ReadLine()); //try to parse string as int variable
  62.                 }
  63.                 catch (Exception) { } //catch invalid input exception
  64.  
  65.                 if ((intJob >= 1) && (intJob <= 3)) //ensure entered int is >= 1 but <=3
  66.                 { validUserInput3 = true; }
  67.                 else { Console.WriteLine("Invalid Input.  "); }
  68.             }
  69.  
  70.             Console.WriteLine("You have selected " + intJob);
  71.             if (intHair == 1)
  72.             {
  73.                 hairColour = "brown";
  74.             }
  75.             else if (intHair == 2)
  76.             {
  77.                 hairColour = "blonde";
  78.             }
  79.             else if (intHair == 3)
  80.             {
  81.                 hairColour = "red";
  82.             }
  83.  
  84.             if (intRace == 1)
  85.             {
  86.                 raceType = "human";
  87.             }
  88.             else if (intRace == 2)
  89.             {
  90.                 raceType = "dwarf";
  91.             }
  92.             else if (intRace == 3)
  93.             {
  94.                 raceType = "elf";
  95.             }
  96.  
  97.             if (intJob == 1)
  98.             {
  99.                 jobType = "Warrior";
  100.             }
  101.             else if (intJob == 2)
  102.             {
  103.                 jobType = "Mage";
  104.             }
  105.             else if (intJob == 3)
  106.             {
  107.                 jobType = "Thief";
  108.             }
  109.  
  110.             Console.WriteLine("You have chosen to be a " + hairColour + "-haired " + raceType + " " + jobType + ".");
  111.             Console.WriteLine("Press any key to terminate");
  112.             Console.ReadKey();
  113.         }
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement