I’m a beginner trying to make a very basic calculator.
I have a problem with division, though;
For some reasons, the result is always rounded down not matter what:
Console.WriteLine("First Argument ?");
int Arg1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Second argument ?");```
int Arg2 = Convert.ToInt32(Console.ReadLine());
float OpDiv = Arg1 / Arg2;
Console.WriteLine($"The result is {OpDiv}");
For example here, 11 / 3 returns 3, instead of 3.66666666…
What have I done wrong ???
>Solution :
Change to:
Console.WriteLine("First Argument ?");
int Arg1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Second argument ?");
int Arg2 = Convert.ToInt32(Console.ReadLine());
float OpDiv = (float)Arg1 / Arg2;
Console.WriteLine($"The result is {OpDiv}");