Co jest w tym kodzie nie tak? Dopiero zaczynam uczyć się C# i pewnie to jakiś głupi błąd
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Kalkulator
{
class Program
{
static void Main(string[] args)
{
int N = int.Parse(Console.ReadLine());
string wyrazenie;
for (int i = 0; i < N; i++)
{
wyrazenie = Console.ReadLine();
int suma = wyrazenie[0]- 48;
for (int j = 2; j<wyrazenie.Length; j+=2)
{
if (wyrazenie[j - 1] == '+')
{
suma += wyrazenie[j] - 48;
}
else if (wyrazenie[j - 1] == '-')
{
suma -= wyrazenie[j] - 48;
}
}
Console.WriteLine(suma);
Console.Read();
}
}
}
}
created
last reply
- 11
replies
- 907
views
- 6
users
- 2
likes
- 3
links