Ant 6729

Ant 6729

  • NA
  • 87
  • 2k

Cycle my question

Jun 29 2019 5:10 PM
Hello I need to ask user until he loads write answer
  1. using System;  
  2. namespace _3_??  
  3. {  
  4. public delegate int BinaryOp(int x, int y);  
  5. public class SimpleMath  
  6. {  
  7. public static int Add(int x, int y)  
  8. return x + y; }  
  9. }  
  10. class Program  
  11. {  
  12. static void MyMethod()  
  13. {  
  14. int userresult;  
  15. Console.WriteLine("Insert sum of x and y");  
  16. userresult = Convert.ToInt16(Console.ReadLine());  
  17. //return {int userresult};  
  18. }  
  19. static void Main(string[] args)  
  20. {  
  21. BinaryOp b = new BinaryOp(SimpleMath.Add);  
  22. string useranswer;  
  23. int userresult;  
  24. int pcresult;  
  25. Console.WriteLine("Insert first number");  
  26. int x = (Convert.ToInt16(Console.ReadLine()));  
  27. Console.WriteLine("Insert second number");  
  28. int y = (Convert.ToInt16(Console.ReadLine()));  
  29. Console.WriteLine("Insert sum of x and y");  
  30. userresult = (Convert.ToInt16(Console.ReadLine()));  
  31. pcresult = b(x, y);  
  32. if (userresult != pcresult)  
  33. {  
  34. Console.WriteLine("Something wrong with your calculations, man..." + "\n" + "Would you like to continue...? (y/n) : ");  
  35. useranswer = Convert.ToString(Console.ReadLine());  
  36. switch(useranswer)  
  37. {  
  38. case "y":  
  39. MyMethod();  
  40. break;  
  41. case "n":  
  42. Console.WriteLine("If I were you, I’d better practice over....You never know...");  
  43. break;  
  44. default:  
  45. break;  
  46. }  
  47. }  
  48. else  
  49. {  
  50. Console.WriteLine("Right");  
  51. }  
  52. }  
  53. }  
  54. }  
Could you help me? 

Answers (2)