Advertisement
skipter

C# If + Methods

Jun 20th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 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. namespace Arrays_and_Methods___Exercise
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int messageCount = int.Parse(Console.ReadLine());
  13.             string output = string.Empty;
  14.             for (int i = 0; i < messageCount; i++)
  15.             {
  16.                 string message = Console.ReadLine();
  17.                 if (message == "success")
  18.                 {
  19.                     string operation = Console.ReadLine();
  20.                     string messageOne = Console.ReadLine();
  21.                     output = SuccessMessage(operation, messageOne);
  22.                     Console.WriteLine(output);
  23.                 } else if (message == "error")
  24.                 {
  25.                     string messageTwo = Console.ReadLine();
  26.                     int code = int.Parse(Console.ReadLine());
  27.                     output = ErrorMessage(messageTwo, code);
  28.                     Console.WriteLine(output);
  29.                 } else
  30.                 {
  31.                     continue;
  32.                 }
  33.             }
  34.         }
  35.        public static string ErrorMessage(string operation, int code)
  36.         {
  37.             string reason = "Invalid Client Data";
  38.             if (code < 0)
  39.             {
  40.                 reason = "Internal System Failure";
  41.             }
  42.             string output = $@"Error: Failed to execute {operation}.
  43. ==============================
  44. Error Code: {code}.
  45. Reason: {reason}.";
  46.             return output;
  47.         }
  48.         public static string SuccessMessage(string operation, string messageOne)
  49.         {
  50.             string output = $@"Successfully executed {operation}.
  51. ==============================
  52. Message: {messageOne}.";
  53.             return output;
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement