Thursday, December 19, 2013

If Statement-Flow Chat and Code Example

In this case the program want the user enter number 0 or 1 and out of this it will print the message "Invalid number...!", and if user doesn't enter any numbers it will show the message "You didn't enter any numbers...!"
Let's start!

Code:
using System;

namespace Bool_Value
{
    class Program
    {
        static void Main(string[] args)
        {
           
           
            int b;
            string userValue = "";
            Console.WriteLine("Enter number 0 or 1: ");

            userValue = Console.ReadLine();

            if (userValue != "")
            {
                b = Convert.ToInt32(userValue);
                if (b == 1)
                {
                    Console.WriteLine(b);
                }
                else if (b == 0)
                {
                    Console.WriteLine(b);
                }
                else
                {
                    Console.WriteLine("Invalid number...!");
                }
            }
            else
            {
                Console.WriteLine("You didn't enter any numbers...!");
            }
           
           
             Console.ReadLine();
           
        }
    }
}

Flow Chat:



Download project file here