private void determineEligibilityButton_Click_1(object sender, EventArgs e) { int age; bool testAge = int.TryParse(ageTextBox.Text, out age); if (!testAge) { validLabel.Text = "Plese enter a valid age"; eligibleLabel.Text = " "; } int years; bool testYears = int.TryParse(yearsInUSTextBox.Text, out years); if (!testYears) { validLabel.Text = "Plese enter a valid number of years"; eligibleLabel.Text = " "; } int priorTerms; bool testTerms = int.TryParse(priorTermsTextBox.Text, out priorTerms); if (!testTerms) { validLabel.Text = "Plese enter a valid number of terms"; eligibleLabel.Text = " "; } bool citizen = false; if (citizenCheckBox.Checked) { citizen = true; } bool rebelled = false; if (rebelledUSCheckBox.Checked) { rebelled = true; } if (testTerms && testYears && testAge) { Eligibility eligiblePrez = new Eligibility(age, years, citizen, priorTerms, rebelled); bool couldRun = eligiblePrez.EligiblePrez(); if (couldRun) { eligibleLabel.Text = "You are eligible to run for President of the US!"; validLabel.Text = " "; } else { eligibleLabel.Text = "You are not eligible to run for President of the US!"; validLabel.Text = " "; } } }
static void Main(string[] args) { int ageInt = 0; int years = 0; bool nbc = false; int termServed = 0; bool didRebel = false; if (args.Length == 0) { bool testAge = false; while (!testAge) { Console.Write("How old are you? "); String age = (Console.ReadLine()); testAge = int.TryParse(age, out ageInt); } Console.Write("Are you a natural born US citizen (y/n)? "); String naturalBornCitizen = Console.ReadLine(); if (naturalBornCitizen[0] == 'y' || naturalBornCitizen[0] == 'Y') { nbc = true; } bool testYears = false; while (!testYears) { Console.Write("How many years were you living in the US? "); String yearsInUS = Console.ReadLine(); testYears = int.TryParse(yearsInUS, out years); } bool testTerms = false; while (!testTerms) { Console.Write("How many prior terms have you served? "); String terms = Console.ReadLine(); testTerms = int.TryParse(terms, out termServed); } Console.Write("Have you rebelled against the US (y/n)? "); String rebelled = Console.ReadLine(); if (rebelled[0].Equals('Y') || rebelled[0].Equals('y')) { didRebel = true; } } else if (args.Length == 5) { if (!(int.TryParse(args[0], out ageInt))) { Console.WriteLine("You entered the wrong arguments."); Console.ReadKey(); System.Environment.Exit(1); } if (!(int.TryParse(args[1], out years))) { Console.WriteLine("You entered the wrong arguments."); Console.ReadKey(); System.Environment.Exit(1); } String nborn = args[2]; if (nborn[0].Equals('y') || nborn[0].Equals('Y')) { nbc = true; } if (!(int.TryParse(args[3], out termServed))) { Console.WriteLine("You entered the wrong arguments."); Console.ReadKey(); System.Environment.Exit(1); } String rebel = args[4]; if (rebel[0] == 'y' || rebel[0] == 'Y') { didRebel = true; } } else { Console.WriteLine("You entered the wrong arguments."); Console.ReadKey(); System.Environment.Exit(1); } Eligibility eligiblePrez = new Eligibility(ageInt, years, nbc, termServed, didRebel); bool couldRun = eligiblePrez.EligiblePrez(); if (couldRun) { Console.WriteLine("You are eligible to run for President of the US!"); } else { Console.WriteLine("You are not eligible to run for President of the US!"); } Console.ReadKey(); }