Files
c-sharp/calculator/kalkulatorr.cs

64 lines
1.5 KiB
C#
Raw Permalink Normal View History

2022-05-31 08:46:10 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace calculator
{
public class Kalkulatorr
2022-05-31 09:44:01 +02:00
{
2022-05-31 08:46:10 +02:00
private int szam1 = 0;
private int szam2 = 0;
private char muvjel;
private int eredm = 0;
2022-05-31 09:44:01 +02:00
private string uzen;
2022-05-31 08:46:10 +02:00
2022-05-31 09:44:01 +02:00
public Kalkulatorr(int szam1, int szam2, char muvjel)
2022-05-31 08:46:10 +02:00
{
this.szam1 = szam1;
this.szam2 = szam2;
this.muvjel = muvjel;
}
public void beker()
{
Console.WriteLine("Adja meg az első számot");
2022-05-31 09:44:01 +02:00
szam1 = int.Parse(Console.ReadLine());
2022-05-31 08:46:10 +02:00
Console.WriteLine("Adja meg a második számot");
2022-05-31 09:44:01 +02:00
szam2 = int.Parse(Console.ReadLine());
2022-05-31 08:46:10 +02:00
Console.WriteLine("Adja meg a műveleti jelet");
2022-05-31 09:44:01 +02:00
muvjel = Convert.ToChar(Console.Read());
2022-05-31 08:46:10 +02:00
}
2022-05-31 09:44:01 +02:00
public int szamolas()
2022-05-31 08:46:10 +02:00
{
switch (muvjel)
{
case '+':
eredm = szam1 + szam2;
break;
case '-':
2022-05-31 09:44:01 +02:00
eredm = szam1 - szam2;
2022-05-31 08:46:10 +02:00
break;
case '*':
eredm = szam1 * szam2;
break;
case '/':
eredm = szam1 / szam2;
break;
default:
uzen = "Hibás műveleti jel";
break;
}
2022-05-31 09:44:01 +02:00
return eredm;
2022-05-31 08:46:10 +02:00
}
}
}