One or two negative numbers Learn programming C#

Lesson:

Flow Control


Exercise:

One or two negative numbers


Objetive:

Create a C# program to prompt the user for two numbers and determine whether both are negative, only one is negative, or neither is negative.


Code:

using System;
public class Exercise27
{
    public static void Main()
    {
        int number1;
        int number2;

        Console.Write("number 1: ");
        number1 = Convert.ToInt32(Console.ReadLine());

        Console.Write("number 2: ");
        number2 = Convert.ToInt32(Console.ReadLine());

        if ((number1 < 0) && (number2 < 0))
            Console.WriteLine("the numbers are negative");

        else if ((number1 < 0) || (number2 < 0))
            Console.WriteLine("one is negative");

        else
            Console.WriteLine("none is negative");
    }
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.