If else in C#

Making Decisions

In programming some problems require making decisions.
A decision making is a basic programming construct that allows execution of instructions if a condition is true.

Example-1

	Write a program (Speed) that allows the user to enter the speed that he travels when he is on the road to Dubai. 
	The program with then display a based on his rate of speed.  If he drives faster than 120, he is speeding; 
	otherwise he is driving within the speed limit.

Steps

Determine if user is driving over the speed limit and display appropriate messages
	if (speed > 120)
		{
			outputLabel.Text = "You are SPEEDING!"
		}
		else
		{
			outputLabel.Text = "You are within the speed limit."
		}
	

Example-2

	Write a program (SalesBonus) that allows a salesman to input the amount of sales he has made this month.  
	The program will give a message telling him if he will get a bonus.
	
The company gives a bonus of AED 500.00 (BONUS) if monthly sales are more than 25,000.00 (HIGH_SALES).

Steps

Determine if user is driving over the speed limit and display appropriate messages
	if (sales > HIGH_SALES)
		{
			MessageBox.Show("You earned a bonus of " + BONUS.ToString("c"));
		}
		else
		{
			MessageBox.Show("Sorry, you sales are less than " + HIGH_SALES.ToString("c"));
		}
	


For more details, please contact me here.
Date of last modification: March 17, 2019