Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Uppgift_1
- {
- class Program
- {
- static void RepeatString(int num, string str)
- {
- for (int i = 0; i < num; i++)
- Console.WriteLine(str);}
- static void Main(string[] args)
- {
- {
- int num;
- int num2;
- string strone;
- string strtwo;
- string textNumber;
- string textNumber2;
- bool run = true;
- string choice;
- string sign;
- while (run)
- {
- Console.WriteLine("1 - Kalkylator");
- Console.WriteLine("2 - Addera två stränger");
- Console.WriteLine("3 - räkna");
- Console.WriteLine("4 - Multiplicera två siffror");
- Console.WriteLine("5 - Exit");
- choice = Console.ReadLine();
- if (choice == "1")
- {
- Console.Write("Enter a number: ");
- textNumber = Console.ReadLine();
- Console.Write("Enter a second number: ");
- textNumber2 = Console.ReadLine();
- Console.Write("Enter a sign: ");
- sign = Console.ReadLine();
- Int32.TryParse(textNumber, out num);
- Int32.TryParse(textNumber2, out num2);
- if (sign == "+")
- {
- Console.Write(num + " + " + num2 + " = ");
- num = num + num2;
- Console.WriteLine(num);
- }
- else if (sign == "-")
- {
- Console.Write(num + " - " + num2 + " = ");
- num = num - num2;
- Console.WriteLine(num);
- }
- else if (sign == "*")
- {
- Console.Write(num + " * " + num2 + " = ");
- num = num * num2;
- Console.WriteLine(num);
- }
- else
- {
- if (num2 == 0)
- {
- Console.WriteLine("Error");
- }
- else
- {
- Console.Write(num + " / " + num2 + " = ");
- num = num / num2;
- Console.WriteLine(num);
- }
- }
- }
- else if (choice == "2")
- {
- Console.Write("Enter the first word: ");
- strone = Console.ReadLine();
- Console.Write("Enter the second word: ");
- strtwo = Console.ReadLine();
- Console.WriteLine(strone + strtwo);
- }
- else if (choice == "3")
- {
- string text;
- Console.Write("Enter a number: ");
- text = Console.ReadLine();
- Int32.TryParse(text, out num);
- Console.Write("Enter a string: ");
- text = Console.ReadLine();
- RepeatString(num, text);
- Console.ReadLine();
- }
- else if (choice == "4")
- {
- Console.Write("Enter the first number: ");
- strone = Console.ReadLine();
- Console.Write("Enter the second number: ");
- strtwo = Console.ReadLine();
- Int32.TryParse(strone, out num);
- Int32.TryParse(strtwo, out num2);
- num *= num2;
- Console.WriteLine("Total: " + num);
- }
- else if (choice == "5")
- {
- run = false;
- }
- else
- {
- Console.WriteLine("You are dumb");
- }
- }
- Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement