Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Homework1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int attCount = 0;
  10.             int attCount2 = 0;
  11.             int maxAttempts = 3;
  12.             int num1 = 5;
  13.             int num2 = 33;
  14.             int num3 = 6;
  15.             int num4 = 40;
  16.             bool isRightAnswer = false;
  17.             bool isRightAnswer2 = false;
  18.             Console.WriteLine("I want to play a game!");
  19.             Console.WriteLine("You must answer these two questions with {0} attempts each!", maxAttempts);
  20.             Console.WriteLine("If you fail...YOU DIE!");
  21.  
  22.            
  23.                 while (attCount < maxAttempts && isRightAnswer)
  24.                 {
  25.                  
  26.                     Console.WriteLine("Question 1, Attempt {0} how much is {1} + {2} ?", attCount + 1, num1, num2);
  27.                     string answer = Console.ReadLine();
  28.                     isRightAnswer = num1 + num2 == int.Parse(answer);
  29.  
  30.  
  31.                     if (!isRightAnswer)
  32.                     {
  33.  
  34.                     Console.WriteLine("you are correct, moving to next question");
  35.  
  36.                     }
  37.                     else
  38.                     {
  39.                         Console.WriteLine("Wrong! you have {0} attempts left", (2 - attCount));
  40.                         attCount++;
  41.  
  42.                     }
  43.                    
  44.                 }
  45.  
  46.                 while (attCount2 < maxAttempts && !isRightAnswer2)
  47.                 {
  48.                
  49.                     Console.WriteLine("Question 2 Attempt {0} how much is {1} + {2} ?", attCount2 + 1, num3, num4);
  50.                     string answer2 = Console.ReadLine();
  51.                     isRightAnswer2 = num3 + num4 == int.Parse(answer2);
  52.  
  53.                     if (!isRightAnswer)
  54.                     {
  55.  
  56.                     Console.WriteLine("You are correct, Your life is safe...until next time...");
  57.  
  58.                     }
  59.                     else
  60.                     {
  61.                     Console.WriteLine("Wrong, you have {0} attempts left", (2 - attCount2));
  62.                     attCount2++;
  63.  
  64.                     }
  65.  
  66.                 }
  67.  
  68.  
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement