Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 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 Uppgift_1
  8. {
  9. class Program
  10. {
  11. static void RepeatString(int num, string str)
  12. {
  13. for (int i = 0; i < num; i++)
  14. Console.WriteLine(str);}
  15.  
  16. static void Main(string[] args)
  17. {
  18. {
  19. int num;
  20. int num2;
  21. string strone;
  22. string strtwo;
  23. string textNumber;
  24. string textNumber2;
  25. bool run = true;
  26. string choice;
  27. string sign;
  28. while (run)
  29.  
  30. {
  31. Console.WriteLine("1 - Kalkylator");
  32. Console.WriteLine("2 - Addera två stränger");
  33. Console.WriteLine("3 - räkna");
  34. Console.WriteLine("4 - Multiplicera två siffror");
  35. Console.WriteLine("5 - Exit");
  36. choice = Console.ReadLine();
  37.  
  38. if (choice == "1")
  39. {
  40. Console.Write("Enter a number: ");
  41. textNumber = Console.ReadLine();
  42. Console.Write("Enter a second number: ");
  43. textNumber2 = Console.ReadLine();
  44. Console.Write("Enter a sign: ");
  45. sign = Console.ReadLine();
  46.  
  47. Int32.TryParse(textNumber, out num);
  48. Int32.TryParse(textNumber2, out num2);
  49.  
  50. if (sign == "+")
  51. {
  52. Console.Write(num + " + " + num2 + " = ");
  53. num = num + num2;
  54. Console.WriteLine(num);
  55. }
  56. else if (sign == "-")
  57. {
  58. Console.Write(num + " - " + num2 + " = ");
  59. num = num - num2;
  60. Console.WriteLine(num);
  61. }
  62. else if (sign == "*")
  63. {
  64. Console.Write(num + " * " + num2 + " = ");
  65. num = num * num2;
  66. Console.WriteLine(num);
  67. }
  68. else
  69. {
  70. if (num2 == 0)
  71. {
  72. Console.WriteLine("Error");
  73. }
  74. else
  75. {
  76. Console.Write(num + " / " + num2 + " = ");
  77. num = num / num2;
  78. Console.WriteLine(num);
  79. }
  80. }
  81. }
  82.  
  83. else if (choice == "2")
  84. {
  85. Console.Write("Enter the first word: ");
  86. strone = Console.ReadLine();
  87. Console.Write("Enter the second word: ");
  88. strtwo = Console.ReadLine();
  89.  
  90. Console.WriteLine(strone + strtwo);
  91. }
  92. else if (choice == "3")
  93. {
  94.  
  95. string text;
  96. Console.Write("Enter a number: ");
  97. text = Console.ReadLine();
  98. Int32.TryParse(text, out num);
  99. Console.Write("Enter a string: ");
  100. text = Console.ReadLine();
  101. RepeatString(num, text);
  102. Console.ReadLine();
  103. }
  104.  
  105. else if (choice == "4")
  106. {
  107. Console.Write("Enter the first number: ");
  108. strone = Console.ReadLine();
  109. Console.Write("Enter the second number: ");
  110. strtwo = Console.ReadLine();
  111.  
  112. Int32.TryParse(strone, out num);
  113. Int32.TryParse(strtwo, out num2);
  114. num *= num2;
  115. Console.WriteLine("Total: " + num);
  116. }
  117. else if (choice == "5")
  118. {
  119. run = false;
  120. }
  121. else
  122. {
  123. Console.WriteLine("You are dumb");
  124. }
  125.  
  126.  
  127.  
  128. }
  129.  
  130. Console.ReadLine();
  131. }
  132. }
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement