Here is the code from the evening class
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace IfExamples { class IfStatements { static void Main(string[] args) { IfStatements ifs = new IfStatements(); //ifs.SimpleIfStatement(); //ifs.IfElseExample(); ifs.SwitchExample(); ifs.PauseIt(); }//end main private void SimpleIfStatement() { Console.WriteLine("Enter an age"); int age = int.Parse(Console.ReadLine()); //equality == //!= not equal if (age > 75) { Console.WriteLine("You are old"); } else { Console.WriteLine("You are a spring chicken"); } }//end SimpleIf private void PauseIt() { Console.WriteLine("Press any key to exit"); Console.ReadKey(); }//end PauseIt private void IfElseExample() { bool isInteger; int score; Console.WriteLine("Enter your test Score"); isInteger= int.TryParse(Console.ReadLine(), out score); if (isInteger == false) { Console.WriteLine("Next time enter a number"); return; } int grade = 0; if (score >= 90) { grade = 4; } else if (score >= 80) { grade = 3; } else if (score >= 70) { grade = 2; } else if (score >= 60) { grade = 1; } else { grade = 0; } Console.WriteLine("Your Grade is {0}", grade); }//end ifelse private void SwitchExample() { int choice; Console.WriteLine("Choose which method to run"); Console.WriteLine("1: SimpleIfStatement"); Console.WriteLine("2: IfElseExample"); Console.WriteLine("3: Exit"); choice = int.Parse(Console.ReadLine()); switch (choice) { case 1: SimpleIfStatement(); break; case 2: IfElseExample(); break; case 3: PauseIt(); break; default: Console.WriteLine("Not a valid choice"); break; } }//end switch //if (number > 0 && number < 100) and //if (number < 0 || number > 100) or }//end class }
No comments:
Post a Comment