Hi, I have made a program to calculate the points required to get into college. The last part of the program that I cannot seem to get working is the
while loop which is intended to repeat the question of what the "int gradeOne" value is, specified by input. The value needs to be H1, or H2 etc right up to H8 or O1 to O8 but the while statement keeps going in an eternal loop no matter what value I enter into it when run. I will write in bold where the problem is. Thanks for any help!
:chuncky::chuncky:
while loop which is intended to repeat the question of what the "int gradeOne" value is, specified by input. The value needs to be H1, or H2 etc right up to H8 or O1 to O8 but the while statement keeps going in an eternal loop no matter what value I enter into it when run. I will write in bold where the problem is. Thanks for any help!
:chuncky::chuncky:
using System; namespace Assignment_2 { class Program { static void Main(string[] args) { //Declare variables string subjectOne, subjectTwo, subjectThree, subjectFour, subjectFive, subjectSix; string gradeOne = "0", gradeTwo = "0", gradeThree = "0", gradeFour = "0", gradeFive = "0", gradeSix = "0"; string loop = "Y"; int gradeOnePoints = 0, gradeTwoPoints = 0, gradeThreePoints = 0; int gradeFourPoints = 0, gradeFivePoints = 0, gradeSixPoints = 0; int average, grandTotal = 0; //Inputs while (loop == "Y") { Console.Write("Enter subject one : "); subjectOne = Console.ReadLine().ToUpper(); Console.Write("Enter subject one grade : "); gradeOne = Console.ReadLine().ToUpper(); // ***** The problem is here ***** while (gradeOne != "H1" || ((gradeOne != "H2") || (gradeOne != "H3") || (gradeOne != "H4") || (gradeOne != "H5") || (gradeOne != "H6") || (gradeOne != "H7") || (gradeOne != "H8") || (gradeOne != "O1") || (gradeOne != "O2") || (gradeOne != "O3") || (gradeOne != "O4") || (gradeOne != "O5") || (gradeOne != "O6") || (gradeOne != "O7") || (gradeOne != "O8"))) { Console.Clear(); Console.WriteLine("Incorrect grade entered, please try again"); Console.Write("Enter subject one grade : "); gradeOne = Console.ReadLine().ToUpper(); } Console.Clear(); Console.Write("Enter subject two : "); subjectTwo = Console.ReadLine().ToUpper(); Console.Write("Enter subject two grade : "); gradeTwo = Console.ReadLine().ToUpper(); Console.Clear(); Console.Write("Enter subject three : "); subjectThree = Console.ReadLine().ToUpper(); Console.Write("Enter subject three grade : "); gradeThree = Console.ReadLine().ToUpper(); Console.Clear(); Console.Write("Enter subject four : "); subjectFour = Console.ReadLine().ToUpper(); Console.Write("Enter subject four grade : "); gradeFour = Console.ReadLine().ToUpper(); Console.Clear(); Console.Write("Enter subject five : "); subjectFive = Console.ReadLine().ToUpper(); Console.Write("Enter subject five grade : "); gradeFive = Console.ReadLine().ToUpper(); Console.Clear(); Console.Write("Enter subject six : "); subjectSix = Console.ReadLine().ToUpper(); Console.Write("Enter subject six grade : "); gradeSix = Console.ReadLine().ToUpper(); //Processes if (gradeOne.ToUpper() == "H1") gradeOnePoints = 100; else if (gradeOne.ToUpper() == "H2") gradeOnePoints = 88; else if (gradeOne.ToUpper() == "H3") gradeOnePoints = 77; else if (gradeOne.ToUpper() == "H4") gradeOnePoints = 66; else if (gradeOne.ToUpper() == "H5") gradeOnePoints = 56; else if (gradeOne.ToUpper() == "H6") gradeOnePoints = 46; else if (gradeOne.ToUpper() == "H7") gradeOnePoints = 37; else if (gradeOne.ToUpper() == "H8") gradeOnePoints = 0; else if (gradeOne.ToUpper() == "O1") gradeOnePoints = 56; else if (gradeOne.ToUpper() == "O2") gradeOnePoints = 46; else if (gradeOne.ToUpper() == "O3") gradeOnePoints = 37; else if (gradeOne.ToUpper() == "O4") gradeOnePoints = 28; else if (gradeOne.ToUpper() == "O5") gradeOnePoints = 20; else if (gradeOne.ToUpper() == "O6") gradeOnePoints = 12; else if (gradeOne.ToUpper() == "O7") gradeOnePoints = 0; else if (gradeOne.ToUpper() == "O8") gradeOnePoints = 0; if (gradeTwo.ToUpper() == "H1") gradeTwoPoints = 100; else if (gradeTwo.ToUpper() == "H2") gradeTwoPoints = 88; else if (gradeTwo.ToUpper() == "H3") gradeTwoPoints = 77; else if (gradeTwo.ToUpper() == "H4") gradeTwoPoints = 66; else if (gradeTwo.ToUpper() == "H5") gradeTwoPoints = 56; else if (gradeTwo.ToUpper() == "H6") gradeTwoPoints = 46; else if (gradeTwo.ToUpper() == "H7") gradeTwoPoints = 37; else if (gradeTwo.ToUpper() == "H8") gradeTwoPoints = 0; else if (gradeTwo.ToUpper() == "O1") gradeTwoPoints = 56; else if (gradeTwo.ToUpper() == "O2") gradeTwoPoints = 46; else if (gradeTwo.ToUpper() == "O3") gradeTwoPoints = 37; else if (gradeTwo.ToUpper() == "O4") gradeTwoPoints = 28; else if (gradeTwo.ToUpper() == "O5") gradeTwoPoints = 20; else if (gradeTwo.ToUpper() == "O6") gradeTwoPoints = 12; else if (gradeTwo.ToUpper() == "O7") gradeTwoPoints = 0; else if (gradeTwo.ToUpper() == "O8") gradeTwoPoints = 0; if (gradeThree.ToUpper() == "H1") gradeThreePoints = 100; else if (gradeThree.ToUpper() == "H2") gradeThreePoints = 88; else if (gradeThree.ToUpper() == "H3") gradeThreePoints = 77; else if (gradeThree.ToUpper() == "H4") gradeThreePoints = 66; else if (gradeThree.ToUpper() == "H5") gradeThreePoints = 56; else if (gradeThree.ToUpper() == "H6") gradeThreePoints = 46; else if (gradeThree.ToUpper() == "H7") gradeThreePoints = 37; else if (gradeThree.ToUpper() == "H8") gradeThreePoints = 0; else if (gradeThree.ToUpper() == "O1") gradeThreePoints = 56; else if (gradeThree.ToUpper() == "O2") gradeThreePoints = 46; else if (gradeThree.ToUpper() == "O3") gradeThreePoints = 37; else if (gradeThree.ToUpper() == "O4") gradeThreePoints = 28; else if (gradeThree.ToUpper() == "O5") gradeThreePoints = 20; else if (gradeThree.ToUpper() == "O6") gradeThreePoints = 12; else if (gradeThree.ToUpper() == "O7") gradeThreePoints = 0; else if (gradeThree.ToUpper() == "O8") gradeThreePoints = 0; if (gradeFour.ToUpper() == "H1") gradeFourPoints = 100; else if (gradeFour.ToUpper() == "H2") gradeFourPoints = 88; else if (gradeFour.ToUpper() == "H3") gradeFourPoints = 77; else if (gradeFour.ToUpper() == "H4") gradeFourPoints = 66; else if (gradeFour.ToUpper() == "H5") gradeFourPoints = 56; else if (gradeFour.ToUpper() == "H6") gradeFourPoints = 46; else if (gradeFour.ToUpper() == "H7") gradeFourPoints = 37; else if (gradeFour.ToUpper() == "H8") gradeFourPoints = 0; else if (gradeFour.ToUpper() == "O1") gradeFourPoints = 56; else if (gradeFour.ToUpper() == "O2") gradeFourPoints = 46; else if (gradeFour.ToUpper() == "O3") gradeFourPoints = 37; else if (gradeFour.ToUpper() == "O4") gradeFourPoints = 28; else if (gradeFour.ToUpper() == "O5") gradeFourPoints = 20; else if (gradeFour.ToUpper() == "O6") gradeFourPoints = 12; else if (gradeFour.ToUpper() == "O7") gradeFourPoints = 0; else if (gradeFour.ToUpper() == "O8") gradeFourPoints = 0; if (gradeFive.ToUpper() == "H1") gradeFivePoints = 100; else if (gradeFive.ToUpper() == "H2") gradeFivePoints = 88; else if (gradeFive.ToUpper() == "H3") gradeFivePoints = 77; else if (gradeFive.ToUpper() == "H4") gradeFivePoints = 66; else if (gradeFive.ToUpper() == "H5") gradeFivePoints = 56; else if (gradeFive.ToUpper() == "H6") gradeFivePoints = 46; else if (gradeFive.ToUpper() == "H7") gradeFivePoints = 37; else if (gradeFive.ToUpper() == "H8") gradeFivePoints = 0; else if (gradeFive.ToUpper() == "O1") gradeFivePoints = 56; else if (gradeFive.ToUpper() == "O2") gradeFivePoints = 46; else if (gradeFive.ToUpper() == "O3") gradeFivePoints = 37; else if (gradeFive.ToUpper() == "O4") gradeFivePoints = 28; else if (gradeFive.ToUpper() == "O5") gradeFivePoints = 20; else if (gradeFive.ToUpper() == "O6") gradeFivePoints = 12; else if (gradeFive.ToUpper() == "O7") gradeFivePoints = 0; else if (gradeFive.ToUpper() == "O8") gradeFivePoints = 0; if (gradeSix.ToUpper() == "H1") gradeSixPoints = 100; else if (gradeSix.ToUpper() == "H2") gradeSixPoints = 88; else if (gradeSix.ToUpper() == "H3") gradeSixPoints = 77; else if (gradeSix.ToUpper() == "H4") gradeSixPoints = 66; else if (gradeSix.ToUpper() == "H5") gradeSixPoints = 56; else if (gradeSix.ToUpper() == "H6") gradeSixPoints = 46; else if (gradeSix.ToUpper() == "H7") gradeSixPoints = 37; else if (gradeSix.ToUpper() == "H8") gradeSixPoints = 0; else if (gradeSix.ToUpper() == "O1") gradeSixPoints = 56; else if (gradeSix.ToUpper() == "O2") gradeSixPoints = 46; else if (gradeSix.ToUpper() == "O3") gradeSixPoints = 37; else if (gradeSix.ToUpper() == "O4") gradeSixPoints = 28; else if (gradeSix.ToUpper() == "O5") gradeSixPoints = 20; else if (gradeSix.ToUpper() == "O6") gradeSixPoints = 12; else if (gradeSix.ToUpper() == "O7") gradeSixPoints = 0; else if (gradeSix.ToUpper() == "O8") gradeSixPoints = 0; if (subjectOne == "MATHS" && (gradeOne == "H1" || gradeOne == "H2" || gradeOne == "H3" || gradeOne == "H4" || gradeOne == "H5" || gradeOne == "H6")) gradeOnePoints += 25; if (subjectTwo == "MATHS" && (gradeTwo == "H1" || gradeTwo == "H2" || gradeTwo == "H3" || gradeTwo == "H4" || gradeTwo == "H5" || gradeTwo == "H6")) gradeTwoPoints += 25; if (subjectThree == "MATHS" && (gradeThree == "H1" || gradeThree == "H2" || gradeThree == "H3" || gradeThree == "H4" || gradeThree == "H5" || gradeThree == "H6")) gradeThreePoints += 25; if (subjectFour == "MATHS" && (gradeFour == "H1" || gradeFour == "H2" || gradeFour == "H3" || gradeFour == "H4" || gradeFour == "H5" || gradeFour == "H6")) gradeFourPoints += 25; if (subjectFive == "MATHS" && (gradeFive == "H1" || gradeFive == "H2" || gradeFive == "H3" || gradeFive == "H4" || gradeFive == "H5" || gradeFive == "H6")) gradeFivePoints += 25; if (subjectSix == "MATHS" && (gradeSix == "H1" || gradeSix == "H2" || gradeSix == "H3" || gradeSix == "H4" || gradeSix == "H5" || gradeSix == "H6")) gradeSixPoints += 25; grandTotal = gradeOnePoints + gradeTwoPoints + gradeThreePoints + gradeFourPoints + gradeFivePoints + gradeSixPoints; average = grandTotal / 6; //Outputs Console.Clear(); Console.WriteLine("Grade Report"); Console.WriteLine("==============================="); Console.WriteLine("Subject Grade Points"); Console.WriteLine("{0,-10}{1,6}{2,11}", subjectOne.ToLower(), gradeOne, gradeOnePoints); Console.WriteLine("{0,-10}{1,6}{2,11}", subjectTwo.ToLower(), gradeTwo, gradeTwoPoints); Console.WriteLine("{0,-10}{1,6}{2,11}", subjectThree.ToLower(), gradeThree, gradeThreePoints); Console.WriteLine("{0,-10}{1,6}{2,11}", subjectFour.ToLower(), gradeFour, gradeFourPoints); Console.WriteLine("{0,-10}{1,6}{2,11}", subjectFive.ToLower(), gradeFive, gradeFivePoints); Console.WriteLine("{0,-10}{1,6}{2,11}", subjectSix.ToLower(), gradeSix, gradeSixPoints); Console.WriteLine(""); Console.WriteLine("Your total points are :{0,4}", grandTotal); Console.WriteLine("Average points :{0,4}", average); Console.WriteLine("==============================="); Console.WriteLine(""); Console.Write("Would you like to calculate again? (Y/N) : "); loop = Console.ReadLine().ToUpper(); Console.Clear(); } } } }
Last edited by a moderator: