using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NumberExamples
{
class Program
{
///
/// This program shows examples of integers
/// and doubles with math operators
/// Steve Conger 10/6/2016
///
///
static void Main(string[] args)
{
//integers and doubles
//operators + - * / %
//decaring number variables
string name;
int number;
int number2;
int answer;
double answer2;
double number3;
//getting values from the user
//anything entered on the console is a string
//it must be converted into the appropriate
//type of number
Console.WriteLine("Enter the first Integer");
number = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the second Integer");
number2 = int.Parse(Console.ReadLine());
//this takes a console entry and converts into a double
//(with decimal places)
Console.WriteLine("Enter a meal amount");
number3 = double.Parse(Console.ReadLine());
answer = number + number2;
Console.WriteLine("The sum of {0} + {1} = {2}", number, number2, answer);
answer = number2 / number;
Console.WriteLine("The quotient of {0} / {1} = {2}", number2, number, answer);
answer = number2 % number;
Console.WriteLine("The remainder of {0} / {1} = {2}", number2, number, answer);
//this casts the integer number2 into a double. it allows the division
//to return decimal places
answer2= (double)number2 / number;
//Math is a built in library of math functions.
//Unlike the format codes this actually changes
//the underlying number
answer2 = Math.Round(answer2, 2);
//{0:F@} would format the number to only show 2 decimal places
//but it does not change the underlying numbers
//c formats the number to look like currency
Console.WriteLine("The double quotient of {0} / {1} = {2}", number2, number, answer2);
Console.WriteLine("The double quotient of {0} / {1} = {2:C}", number2, number, answer2);
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}//end main
}//end program
}//end namespace
Thursday, October 6, 2016
Using Integers and doubles
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment