4
I’m doing a simple C# exercise in which I have to receive two numbers, compare them and print out which is the largest or whether they are equal.
When I start the program, I can only put the first number, and before putting the second, the program already returns the comparison, with numbers that have nothing to do with what I put.
For example: if I put 1 to the first, the program prints this:
"Digite outro número: 49 é maior que 13.Pressione qualquer tecla para continuar. . ."
I’m using the Read();
the wrong way? What would be another way to do this program?
class Program
{
static void Main(string[] args)
{
Console.Write("Digite um número: ");
int a = Console.Read();
Console.Write("Digite outro número: ");
int b = Console.Read();
if (a > b)
{
Console.Write("{0} é maior que {1}.", a, b);
}
else if (b > a)
{
Console.Write("{0} é maior que {1}.", b, a);
}
else
{
Console.Write("Os dois números são iguais");
}
}
}
Very well put: "the code does what you say, not what you want!" This helps to improve the quality of the questions!
– Mateus