Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class ApplyBonusScoresToScoresWithSwitch
- {
- static void Main()
- {
- //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.
- //Use a switch statement and at the end print the calculated new value in the console.
- Console.Write("Please enter your score in the range [1, 9]: ");
- string userInput = Console.ReadLine();
- int score;
- bool isCorrectInput = int.TryParse(userInput,out score);
- if (isCorrectInput)
- {
- Console.WriteLine("Your score was: {0}", score);
- switch (score)
- {
- case 1:
- case 2:
- case 3:
- {
- score = score * 10;
- Console.WriteLine("Your new bonus score is: {0}", score);
- }
- break;
- case 4:
- case 5:
- case 6:
- {
- score = score * 100;
- Console.WriteLine("Your new bonus score is: {0}", score);
- }
- break;
- case 7:
- case 8:
- case 9:
- {
- score = score * 1000;
- Console.WriteLine("Your new bonus score is: {0}", score);
- }
- break;
- default:
- {
- Console.WriteLine("Error! The score you have entered is not valid!");
- }
- break;
- }
- }
- else
- {
- Console.WriteLine("Incorrect Input! Your score was not in the range [1, 9]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement