Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ASasitharan__Lab4
- {
- class Program
- {
- static void Main(string[] args)
- {
- //*********************************************************************************************VARIABLES***************************************************************************************************************
- const int MIN_GRADE = 0;
- const int MAX_GRADE = 300;
- string tmpUserInput;
- int scoreInput;
- double [] scores = new double[6];
- int count = 1;
- bool isValid=false;
- double sum = 0;
- double highScore;
- double lowestScore;
- bool restart = true;
- string yesNo;
- bool validYesNo = false;
- double average = 0.0;
- //*********************************************************************************************VARIABLES***************************************************************************************************************
- //loop while restart is true
- while (restart)
- {
- //reseet average variable
- average = 0.0;
- //reset sum variable
- sum = 0.0;
- //resets count to 1
- count = 1;
- //for loop that loops through entire array
- for (int i = 0; i < scores.Length; i++)
- {
- //reset isValid to false
- isValid = false;
- //loop while isValid is false
- while (!isValid)
- {
- //prompt the user for score input and use count to list the game number
- Console.Write("Please enter the score for game " + count + ": ");
- //tmp string user input for bowling scores
- tmpUserInput = Console.ReadLine();
- //run if user input is numeric and parses user input
- if (Int32.TryParse(tmpUserInput, out scoreInput))
- {
- //runs if user input is within valid range
- if (scoreInput >= MIN_GRADE && scoreInput <= MAX_GRADE)
- {
- //assigns score input to array
- scores[i] = scoreInput;
- //sum variable adds up all of the data through each iteration
- sum += scores[i];
- //increment count up by 1
- count++;
- //set isValid to true
- isValid = true;
- }
- //runs if user input is outside of valid range
- else
- {
- //display error message
- Console.WriteLine("\nScores must be between 0 and 300. Please try again.\n");
- }
- }
- //runs if user input is not numeric and an integer
- else
- {
- //display error message
- Console.WriteLine("\nScores must be numeric, whole numbers only, no decimals. Please try again.\n");
- }
- }
- } //end of for loop
- //clears the console
- Console.Clear();
- //border
- Console.WriteLine("======================================================================================================================\n");
- //list all of the scores
- Console.WriteLine("Game 1: " + scores[0] + " Game 2: " + scores[1] + " Game 3: " + scores[2] + " Game 4: " + scores[3] + " Game 5: " + scores[4] + " Game 6: " + scores[5]);
- //border
- Console.WriteLine("\n======================================================================================================================\n");
- //sets high score to be equal to first array value
- highScore = scores[0];
- //loops through the array
- for (int j = 0; j < scores.Length; j++)
- {
- //runs if the current array value is greater than the current high score
- if (scores[j] > highScore)
- {
- //changes the highest score to current array value
- highScore = scores[j];
- }
- }//end of for loop
- //sets lowest score to be equal to first array value
- lowestScore = scores[0];
- //loops through the array
- for (int k = 0; k < scores.Length; k++)
- {
- //runs if the current array value is greater than the current lowest score
- if (scores[k] < lowestScore)
- {
- //changes the lowest score to current array value
- lowestScore = scores[k];
- }
- }
- average = sum / scores.Length;
- //displays average score for the bowler
- Console.WriteLine("Average Score for Bowler: " + Math.Round(average));
- //displays highest score
- Console.WriteLine("\nHigh Score for Bowler: " + highScore);
- //displays lowest score
- Console.WriteLine("\nLow Score for Bowler: " + lowestScore);
- //reset validYesNo value to false
- validYesNo = false;
- //loop while validYesNo is false
- while (!validYesNo)
- {
- //prompt user to enter y or n
- Console.WriteLine("\n\nWould you like to process another set of bowler scores? ");
- Console.Write("\nPlease enter Y to continue or N to exit: ");
- //user input for yes or no
- yesNo = Console.ReadLine();
- //runs if user enter y
- if (yesNo == "Y" || yesNo == "y")
- {
- //clears the console
- Console.Clear();
- //sets validYesNo to true to break out of loop
- validYesNo = true;
- }
- //runs if user enters n
- else if (yesNo == "N" || yesNo == "n")
- {
- //set restart to false to break out of main loop
- restart = false;
- //sets validYesNo to true to break out of current loop
- validYesNo = true;
- }
- //runs if user enteres anything besides y or n
- else
- {
- //display error message
- Console.WriteLine("\n\nENTRY ERROR");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement