Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.15 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 calc
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // Määritellään muuttujat
  14.             int numOne = 0;
  15.             int numTwo = 0;
  16.             int result = 0;
  17.             string operation = "+";
  18.  
  19.             // Käyttäjä syöttää luvut ja toiminnon
  20.                 Console.WriteLine("Anna kokonaisluku");
  21.                 try
  22.                 {
  23.                     numOne = int.Parse(Console.ReadLine());
  24.                 }
  25.                 catch
  26.                 {
  27.  
  28.                     Console.WriteLine("Numbers only, son! Re-enter the number.");
  29.                     numOne = int.Parse(Console.ReadLine());
  30.                 }
  31.                 Console.WriteLine("Anna laskutoimitus + tai - tai * tai /");
  32.                 operation = Console.ReadLine();
  33.  
  34.                 Console.WriteLine("Anna toinen kokonaisluku");
  35.                 try
  36.                 {
  37.                     numTwo = int.Parse(Console.ReadLine());
  38.                 }
  39.                 catch
  40.                 {
  41.                     Console.WriteLine("Numbers only, son! Re-enter the number.");
  42.                     numTwo = int.Parse(Console.ReadLine());
  43.                 }
  44.             // Suoritetaan lasku käyttäjän antamilla toiminnoilla
  45.             if (operation == "*")
  46.             {
  47.                 result = numOne * numTwo;
  48.             }
  49.             if (operation == "+")
  50.             {
  51.                 result = numOne + numTwo;
  52.             }
  53.             if (operation == "/")
  54.             {
  55.                 if (numTwo == 0)
  56.                 {
  57.                     result = 0;
  58.                 }
  59.                 else
  60.                 {
  61.                     result = numOne / numTwo;
  62.                 }
  63.  
  64.             }
  65.             if (operation == "-")
  66.             {
  67.                 result = numOne - numTwo;
  68.             }
  69.  
  70.             // Output
  71.             Console.WriteLine("Tulos on " + result);
  72.  
  73.             // KEEP THE SYSTME RUNNINK PLS
  74.             Console.ReadLine();
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement