ntodorova

10_ApplyBonusScores

Nov 2nd, 2012
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2.  
  3. class ApplyBonusScores
  4. {
  5.     static void Main()
  6.     {
  7.         int digit;
  8.  
  9.         Console.Write("Please enter а number into the range [1..9]: ");
  10.         string str = Console.ReadLine();
  11.  
  12.         if (!int.TryParse(str, out digit))
  13.         {
  14.             Console.WriteLine("Invalid number: {0}", str);
  15.         }
  16.         else
  17.         {
  18.             while (digit <= 1 || digit >= 9)
  19.             {
  20.                 Console.WriteLine("Please enter correct number!");
  21.                 string strSecond = Console.ReadLine();
  22.  
  23.                 if (!int.TryParse(strSecond, out digit))
  24.                 {
  25.                     Console.WriteLine("Invalid number: {0}", strSecond);
  26.                 }
  27.             }
  28.  
  29.             switch (digit)
  30.             {
  31.                 case 1:
  32.                 case 2:
  33.                 case 3:
  34.                     digit *= 10;
  35.                     break;
  36.  
  37.                 case 4:
  38.                 case 5:
  39.                 case 6:
  40.                     digit *= 100;
  41.                     break;
  42.  
  43.                 case 7:
  44.                 case 8:
  45.                 case 9:
  46.                     digit *= 1000;
  47.                     break;
  48.  
  49.                 default:
  50.                     Console.WriteLine("Wrong number entered!");
  51.                     break;
  52.             }
  53.  
  54.             Console.WriteLine("The new value is {0}.", digit);
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment