Advertisement
sylviapsh

Apply Bonus Scores To Scores With a Switch

Dec 28th, 2012
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. using System;
  2. class ApplyBonusScoresToScoresWithSwitch
  3. {
  4.   static void Main()
  5.   {
  6.     //Write a program that applies bonus scores to given scores in the range [1..9]. The program reads a digit as an input. If the digit is between 1 and 3, the program multiplies it by 10; if it is between 4 and 6, multiplies it by 100; if it is between 7 and 9, multiplies it by 1000. If it is zero or if the value is not a digit, the program must report an error.
  7.     //Use a switch statement and at the end print the calculated new value in the console.
  8.  
  9.     Console.Write("Please enter your score in the range [1, 9]: ");
  10.     string userInput = Console.ReadLine();
  11.     int score;
  12.     bool isCorrectInput = int.TryParse(userInput,out score);
  13.    
  14.     if (isCorrectInput)
  15.     {
  16.       Console.WriteLine("Your score was: {0}", score);
  17.       switch (score)
  18.       {
  19.       case 1:
  20.       case 2:
  21.       case 3:
  22.         {
  23.           score = score * 10;
  24.           Console.WriteLine("Your new bonus score is: {0}", score);
  25.         }
  26.         break;
  27.       case 4:
  28.       case 5:
  29.       case 6:
  30.         {
  31.           score = score * 100;
  32.           Console.WriteLine("Your new bonus score is: {0}", score);
  33.         }
  34.         break;
  35.       case 7:
  36.       case 8:
  37.       case 9:
  38.         {
  39.           score = score * 1000;
  40.           Console.WriteLine("Your new bonus score is: {0}", score);
  41.         }
  42.         break;
  43.       default:
  44.         {
  45.           Console.WriteLine("Error! The score you have entered is not valid!");
  46.         }
  47.         break;
  48.       }
  49.     }
  50.       else
  51.         {
  52.           Console.WriteLine("Incorrect Input! Your score was not in the range [1, 9]");
  53.         }
  54.     }
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement