Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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.
- */
- using System;
- class BonusScores
- {
- static void Main()
- {
- byte digit;
- int result = 0;
- digit = InputData();
- switch (digit)
- {
- case 1:
- case 2:
- case 3:
- {
- result = digit * 10;
- break;
- }
- case 4:
- case 5:
- case 6:
- {
- result = digit * 100;
- break;
- }
- case 7:
- case 8:
- case 9:
- {
- result = digit * 1000;
- break;
- }
- default:
- {
- Console.WriteLine("Error! Please enter a value between 1 and 9" + Environment.NewLine);
- break;
- }
- }
- if (result != 0)
- {
- OutputData(result);
- }
- Main();
- }
- static byte InputData()
- {
- byte digit;
- string invalidInput = "Please enter a value between 1 and 9" + Environment.NewLine;
- Console.WriteLine("Enter a digit : ");
- while (!(byte.TryParse(Console.ReadLine(), out digit) && digit >=0 && digit <= 9))
- {
- Console.WriteLine(invalidInput);
- Console.WriteLine("Enter a digit: ");
- }
- return digit;
- }
- static void OutputData(int result)
- {
- Console.WriteLine("Result: {0}" + Environment.NewLine, result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment