SHARE
TWEET

C# - Conditional Statements - Exercise 3

cherokee Nov 24th, 2012 21 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. class BiggestOfThree
  4. {
  5.     static void Main()
  6.     {
  7.         //Write a program that finds the biggest of three integers using nested if statements.
  8.         int numOne = 0, numTwo = 0, numThree = 0;
  9.         bool noError = true;
  10.         bool equalNumbers = false;
  11.         Console.Title = "Find the biggest number out of three";
  12.         Console.WriteLine("Enter three different integers and program will find the biggest one.");
  13.         do
  14.         {
  15.             do
  16.             {
  17.                 Console.Write("Number 1: ");
  18.                 noError = int.TryParse(Console.ReadLine(), out numOne);
  19.             } while (!noError);
  20.             do
  21.             {
  22.                 Console.Write("Number 2: ");
  23.                 noError = int.TryParse(Console.ReadLine(), out numTwo);
  24.             } while (!noError);
  25.             do
  26.             {
  27.                 Console.Write("Number 3: ");
  28.                 noError = int.TryParse(Console.ReadLine(), out numThree);
  29.             } while (!noError);
  30.             if ((numOne == numTwo) || (numOne == numThree) || (numTwo == numThree))
  31.             {
  32.                 Console.WriteLine("You have entered 2 or 3 numbers with equal values. Please reenter all.");
  33.                 equalNumbers = true;
  34.             }
  35.             else
  36.             {
  37.                 equalNumbers = false;
  38.             }
  39.         } while (equalNumbers);
  40.         if (numOne > numTwo)
  41.         {
  42.             if (numOne > numThree)
  43.             {
  44.                 Console.WriteLine("First number is the biggest: {0}", numOne);
  45.             }
  46.             else
  47.             {
  48.                 Console.WriteLine("Third number is the biggest: {0}", numThree);
  49.             }
  50.  
  51.         }
  52.         else if (numTwo > numThree)
  53.         {
  54.             Console.WriteLine("Second number is the biggest: {0}", numTwo);
  55.         }
  56.         else
  57.         {
  58.             Console.WriteLine("Third number is the biggest: {0}", numThree);
  59.         }
  60.  
  61.     }
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top