c# console calculator


SUBMITTED BY: rubenbezdi

DATE: Sept. 9, 2016, 1:39 p.m.

FORMAT: Text only

SIZE: 2.2 kB

HITS: 199083

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ConsoleApplication2
  7. {
  8. class Program
  9. {
  10. static int Main()
  11. {
  12. bool onOffRbez = true;
  13. string inputLine1Rbez;
  14. int inputLine1VarRbez;
  15. string inputLine2Rbez;
  16. int inputLine2VarRbez;
  17. int answerVarRbez;
  18. string answerRbez;
  19. string inputExitRbez;
  20. int inputExitVarRbez = 2;
  21. while (onOffRbez == true)
  22. {
  23. try
  24. {
  25. Console.WriteLine("Type first number of sum");
  26. inputLine1Rbez = Console.ReadLine();
  27. inputLine1VarRbez = Convert.ToInt32(inputLine1Rbez);
  28. Console.WriteLine("Type second number of sum");
  29. inputLine2Rbez = Console.ReadLine();
  30. inputLine2VarRbez = Convert.ToInt32(inputLine2Rbez);
  31. answerVarRbez = inputLine1VarRbez + inputLine2VarRbez;
  32. answerRbez = Convert.ToString(answerVarRbez);
  33. Console.WriteLine(inputLine1Rbez + "+" + inputLine2Rbez + "=" + answerRbez + Environment.NewLine);
  34. Console.WriteLine("Press 1 to continue press 0 to exit");
  35. inputExitRbez = Console.ReadLine();
  36. inputExitVarRbez = Convert.ToInt32(inputExitRbez);
  37. if (inputExitVarRbez == 1)
  38. {
  39. Console.Clear();
  40. }
  41. else
  42. {
  43. onOffRbez = false;
  44. }
  45. }
  46. catch
  47. {
  48. Console.WriteLine("U can only use numbers! Press enter to try again.");
  49. Console.ReadKey();
  50. Console.Clear();
  51. onOffRbez = false;
  52. onOffRbez = true;
  53. }
  54. }
  55. return 0;
  56. }
  57. }
  58. }

comments powered by Disqus