If-Else Programming
If-Else Programming
if (num1 == num2)
{
Console.WriteLine("The two numbers are equal.");
}
else
{
Console.WriteLine("The numbers are not equal");
}
int num1;
if (num1 % 2 == 0)
{
Console.WriteLine("The number is even");
}
else
{
Console.WriteLine("The number is odd");
Console.WriteLine("Thank you for using this program. This will convert any value
in dollars to");
Console.WriteLine("Canadian Dollars, Euro, Indian Rupee and Philippine Peso");
Console.WriteLine("-----------------------------------");
Console.Write("Enter the amount in dollars: $");
dollars = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("-----------------------------------");
Console.WriteLine();
Console.WriteLine("-----------------------------------");
Console.WriteLine("CD - for Canadian Dollars ");
Console.WriteLine("E - for Euro");
Console.WriteLine("IR - for Indian Rupee");
Console.WriteLine("PHP - for Philippine Peso ");
Console.WriteLine("-----------------------------------");
Console.Write("Please enter the desired code for currency you want to convert to:
");
choice = Console.ReadLine();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
switch (choice)
{
case "CD":
convertedValue = dollars * 0.9813;
break;
case "E":
convertedValue = dollars * 0.757;
break;
case "IR":
convertedValue = dollars * 52.53;
break;
case "PHP":
convertedValue = dollars * 49.80;
break;
default:
Console.WriteLine("Invalid input.");
isInputValid = false;
break;
}
if (isInputValid)
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("${0} = {1} in {2}", dollars, convertedValue, choice);
Console.WriteLine("-----------------------------------");
/*
Write a program that calculates and prints the bill for a cellular telephone company. The company
offers two types of service: regular and premium.
Its rates vary depending on what type of service: regular(code R) and premium (code P).
//FOR THE SKELETON OF THE PROGRAM, HERE IS THE CODE. THIS HAS NO COMPUTATIONS YET. JUST THE OVERALL
//ORDER OF OPERATIONS.
string serviceType;
double regularRate, regularFreeMinutes, premiumBaseDollarValue, premiumDayRate, premiumNightRate,
totalBill;
}
else
{
//premium services code goes here
}
//After calculation, print output here.
Console.WriteLine( "Thank you for using our services." );
Console.WriteLine( "Your total bill is $" + totalBill );
}
else
{
//wrong serviceType was keyed in.
Console.WriteLine("Service type is invalid.");
}
//END OF PROGRAM
//THIS IS THE COMPLETE SOLUTION. NOTICE THE NEW VARIABLES ADDED AND ARE USED FOR THE SOLUTION.
//NOTICE AS WELL HOW I NAME MY VARUABLES.
string serviceType;
double regularBasePayment, regularRate, regularFreeMinutes, premiumBasePayment, premiumDayRate,
premiumNightRate, totalBill, minutesToCharge;
//temporary string variables, these strings will hold the input values from the user through
Console.ReadLine
string regularMinuteString, premiumDayMinuteString, premiumNightMinuteString;
//number values to store the converted values of the temporary strings
double regularMinute, premiumDayMinute, premiumNightMinute;
//calculate minutes to charge from the user aside from the Free 50 minutes;
minutesToCharge = regularMinute - regularFreeMinutes;
Console.Write("Enter total number of minutes used for calling during the NIGHT: ");
premiumNightMinuteString = Console.ReadLine();
premiumNightMinute = Convert.ToDouble(premiumNightMinuteString);
//Now that we have the night and day minutes, its time to calculate the total bill
totalBill = premiumBasePayment + (premiumDayMinute * premiumDayRate) +
(premiumNightMinute * premiumNightRate);
}
//After calculation, print output here.
Console.WriteLine( "Thank you for using our services." );
Console.WriteLine( "Your total bill is $" + totalBill );
}
else
{
//wrong serviceType was keyed in.
Console.WriteLine("Service type is invalid.");
}
Console.ReadLine();