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 Siszarp
- {
- class kalkulator
- {
- private int a1, a2;
- private char dzialanie;
- public kalkulator() { }
- public void getValues(int ar1, int ar2, char dzi){
- a1 = ar1;
- a2 = ar2;
- dzialanie = dzi;
- }
- public int oblicz(){
- int wynik = 0;
- switch (dzialanie)
- {
- case '+': wynik = a1 + a2;
- break;
- case '-': wynik = a1 - a2;
- break;
- case '*': wynik = a1 * a2;
- break;
- case '/': wynik = a1 / a2;
- break;
- }
- return wynik;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int a, b;
- char dz;
- string s = " ";
- string[] elementy = new string [3];
- kalkulator k = new kalkulator();
- while (s != "x")
- {
- Console.WriteLine("Podaj co chcesz policzyć:");
- s = Console.ReadLine();
- elementy = s.Split(' ');
- try
- {
- a = Int32.Parse(elementy[0]);
- dz = char.Parse(elementy[1]);
- b = Int32.Parse(elementy[2]);
- }
- catch
- {
- Console.WriteLine("Podane dane niewłaściwe!");
- Console.ReadLine();
- continue;
- }
- Console.WriteLine("{0},{1},{2}", a, b, dz);
- k.getValues(a, b, dz);
- Console.WriteLine("Wynik: {0}", k.oblicz());
- // koniec
- Console.WriteLine("Wpisz x aby wyjść lub enter by kontynuować...");
- s = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement