0

This code should return area and perimeter with the radio, that, does it, though will should addition the odd numbers when the radio is odd, but it does the opposite.

        //int radio;
        float radio, area, perimetro, PI = 3.1416f;
        string texto;
        //float constante = 3.1416f;


        Console.Write("Ingrese Radio del Circulo: ");
        texto = Console.ReadLine();
        radio = int.Parse(texto);

        area = PI * radio * radio;
        perimetro = 2 * PI * radio;

        Console.WriteLine("\nEl area del circulo es: " + area);
        Console.WriteLine("El Perimetro del circulo es: " + perimetro);


        if ((radio % 2) == 0)
        {
            Console.WriteLine("\nSuma Impares: " + (radio + area + perimetro));
        }
        else
        {
            Console.WriteLine("\nEl Radio es Par");
        }

        Console.WriteLine("\nPresione Cualquier tecla para finalizar");
        Console.ReadKey();
    }
}

}

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179

2 Answers2

1

Odd number means if ((radio % 2) == 1)

KKKKeZZZZ
  • 11
  • 5
1

The problem you have is here:

if ((radio % 2) == 0)
{
    Console.WriteLine("\nSuma Impares: " + (radio + area + perimetro));
}
else
{
    Console.WriteLine("\nEl Radio es Par");
}

(radio % 2) == 0 means it is a pair and you are looking for odd instead, so you should do this:

if ((radio % 2) != 0)
{
    Console.WriteLine("\nSuma Impares: " + (radio + area + perimetro));
}
else
{
    Console.WriteLine("\nEl Radio es Par");
}
Juan Medina
  • 565
  • 7
  • 15