Advertisement
Mitax

05.Integer_to_Base

Feb 3rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _05.Integer_to_Base
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             string operation = String.Empty;
  16.             string message = String.Empty;
  17.             int code = 0;
  18.  
  19.             for (int i = 0; i < n; i++)
  20.             {
  21.                 string successOrErrorMessage = Console.ReadLine();
  22.                 if (successOrErrorMessage == "success")
  23.                 {
  24.                     operation = Console.ReadLine();
  25.                     message = Console.ReadLine();
  26.                     var reason = String.Empty;
  27.  
  28.                     var printedMessage = ShowSuccess(operation, message);
  29.                     Console.WriteLine(printedMessage);
  30.                 }
  31.                 else if (successOrErrorMessage == "error")
  32.                 {
  33.                     operation = Console.ReadLine();
  34.                     code = int.Parse(Console.ReadLine());
  35.                     //var reason = String.Empty;
  36.  
  37.                     var printedMessasge = ShowError(operation, code);
  38.                     Console.WriteLine(printedMessasge);
  39.                 }
  40.             }
  41.         }
  42.  
  43.         static string ShowError(string operation, int code)
  44.         {
  45.             var reason = String.Empty;
  46.  
  47.             if (code >= 0)
  48.             {
  49.                 reason = "Invalid Client Data";
  50.             }
  51.             else
  52.             {
  53.                 reason = "Internal System Failure";
  54.             }
  55.  
  56.             var printedMessage = $"Error: Failed to execute {operation}.\n==============================\nError Code: {code}.\nReason: {reason}.";
  57.             return printedMessage;
  58.         }
  59.  
  60.         static string ShowSuccess(string operation, string message)
  61.         {
  62.             var printedMessage = $"Successfully executed {operation}.\n==============================\nMessage: {message}.";
  63.             return printedMessage;
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement