Monday, October 4, 2010

operators and methods: afternoon.

Here is the code we did in class

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

namespace methodExamples
{
class Program
{
double number = 0;
static void Main(string[] args)
{
//* / + - %
Program p = new Program();
// p.BasicOperators();
p.UseCube();
Console.ReadKey();

}

private void BasicOperators()
{
int x=6, y=8;
double a, b;
a = 12.34;
b = 3.75;


double sum = a + b;
double difference = a - b;
double product = a * b;

int quotient = y / x;
int remainder = y % x;

Console.WriteLine("The sum is {0}", sum.ToString());
Console.WriteLine("The difference {0}", difference.ToString());
Console.WriteLine("The product is {0}", product.ToString());
Console.WriteLine("The quotient of integer {0}, and {1} is {2}", y.ToString(), x.ToString(), quotient.ToString());
Console.WriteLine("The remainder is {0}", remainder.ToString());


}//end method BasicOperators

private double Cube(double number)
{
double cubeNumber=number * number * number;
return cubeNumber;
}

private void UseCube()
{

Console.WriteLine("Enter a number");
double myNumber = double.Parse(Console.ReadLine());
double myCube = Cube(myNumber);
Console.WriteLine("The cube of {0} is {1}", myNumber.ToString(), myCube.ToString());
}
}//end class
}//end namespace

No comments:

Post a Comment