Wednesday, October 13, 2010

If then examples (morning)

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

namespace ifmethod
{
class Program
{
/*Steve Conger
* 10/12/2010
* Assignment x
* */

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

int Remainder(int num1, int num2)
{
int modulus;
modulus= num1 % num2;
return modulus;
}//end remainder

void Display()
{

int numberOne, numberTwo;
bool good, isInt;

Console.WriteLine("enter a number");
good = int.TryParse(Console.ReadLine(), out numberOne);

//if (good == false)
//{
// Console.WriteLine("You must Enter an integer");
// return; //end method display
//}
//else
// {
//do something else
//}


Console.WriteLine("enter another number");
isInt = int.TryParse(Console.ReadLine(), out numberTwo);

//this is a way to do it in one statement
//the || means or
if (good == false || isInt == false)
{
Console.WriteLine("You must Enter an integer");
return; //end method display
}

int remain = Remainder(numberOne, numberTwo);

Console.WriteLine("the remainder of {0} divided by {1} = {2}", numberOne.ToString(),
numberTwo.ToString(), remain.ToString());

// SumOfRemainder(remain);

}

void Weather(int degrees)
{
if (degrees >= 100)
{
Console.WriteLine("way too hot");
}
else
if (degrees >= 80)
{
Console.WriteLine("hot");
}
else
if (degrees >= 60)
{
Console.WriteLine("Just right");
}
else
if (degrees >= 40)
{
Console.WriteLine("autumnal");
}
else
{
Console.WriteLine("cold");
}


}

void GetDegrees()
{
Console.WriteLine("Enter a temperature");
int temp = int.Parse(Console.ReadLine());

Weather(temp);
}

//void SumOfRemainder(int r)
//{
// Console.WriteLine(r.ToString());
//}

}//end program class
}//end namespace

No comments:

Post a Comment