Monday, October 11, 2010

IF ELSE IF ELSE

Here is starter code for the assignment;

using System;
using System.Collections.Generic;
using System.Text;

namespace Assignment3Help
{
class Program
{
double grossPay;

static void Main(string[] args)
{
Program p = new Program();
p.Display();
Console.ReadKey();
}

double CalculateGrossPay(double rate, double hours)
{
return rate * hours;
}

void Display()
{
Console.WriteLine("Enter the Rate");
double rate = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the hours");
double hours = double.Parse(Console.ReadLine());
grossPay = CalculateGrossPay(rate, hours);
Console.WriteLine("The Gross pay is {0}", grossPay.ToString("c"));
}//end display

double SocialSecurity()
{
//at or above 5000 30%
//at or above 3000 25%
//at or above 2000 20%
//at or above 1000 15%
//at or above 800 10%
//below 800 0%
double socialSecurity;
if (grossPay >= 5000)
{
socialSecurity = grossPay * .3;
}
else if ( grossPay >=3000)
{
socialSecurity = grossPay * .25;
}
else if (grossPay >= 2000)
{
socialSecurity = grossPay * .2;
}
else if (grossPay >= 1000)
{
socialSecurity = grossPay * .1;
}
else
{
socialSecurity = 0;
}
return socialSecurity;

}

}//class
}

The other code we did
using System;
using System.Collections.Generic;
using System.Text;

namespace OperationsPractice
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
//p.Display();
Console.WriteLine("Enter a temperature");
int temp = int.Parse(Console.ReadLine());
p.IfElseExample(temp);
Console.ReadKey();
}//end main

private int Addition(int num1, int num2)
{
return num1 + num2;
}//end add

private void Display()
{
int number1=0;
int number2;
bool isInt1;
bool isInt2;

Console.WriteLine("Enter the first number");
isInt1 = int.TryParse(Console.ReadLine(), out number1);
if (isInt1 == false)
{
Console.WriteLine("You must enter an integer");
//Console.ReadKey();
return;
}//end if

Console.WriteLine("Enter the Second number");
isInt2 = int.TryParse(Console.ReadLine(), out number2);

if (isInt2 == false)
{
Console.WriteLine("You must enter an integer");
//Console.ReadKey();
return;
}//end if
int sum=Addition(number1, number2);
Console.WriteLine("the sum is {0}", sum );
}//end display

private void IfElseExample(int number)
{
if (number >= 100)
{
Console.WriteLine("It is too hot");
}
else if (number >= 80)
{
Console.WriteLine("Hot");
}
else if (number >= 60)
{
Console.WriteLine("Just right");
}
else if (number >= 40)
{
Console.WriteLine("cool");
}
else
{
Console.WriteLine("Cold");
}

//if(number != 3)
//{
// if (number > 5)
//{
//return;
//}
//else
//{
//}
// }
//else
//{
//do something else
//}
}
}//end class
}//end namespace

No comments:

Post a Comment