So I am having problems with programming a bowling application in c# to calculate 5 different scores, storing them in an array and returning the average, highest and lowest scores, I am having problems with the code for storing the array and returning the scores. Here is what i have so far:
static void Main(string[] args)
{
//Declarations
const double MIN_SCORE = 0;
const double MAX_SCORE = 300;
const int SCORE_COUNT = 5;
int[] scores = new int[SCORE_COUNT]; //stores all the scores
int inputScore; //stores one score
double total = 0; //to total the scores for average
double average; //average the grades
double highScore; //highest score of the games
double lowScore; //lowest score of the games
//INPUT
//loop to get scores
for (int bowler = 0; bowler < scores.Length; bowler++)
{
try
{
//prompt for and get the input
Console.Write("Please enter score for game " + (bowler + 1) + ":");
inputScore = Convert.ToInt16(Console.ReadLine());
//valid range?
if (inputScore > MAX_SCORE || inputScore < MIN_SCORE)
{
Console.WriteLine("Scores must be between " + MIN_SCORE +
" and " + MAX_SCORE + ". Please try again. ");
bowler--;
}
else
{
scores[bowler] = inputScore;
}
}
catch (Exception myEx)
{
Console.WriteLine(myEx.Message + " Please try again. ");
bowler--;
}
//PROCESS
Array.Sort(scores);
//OUTPUT
Console.WriteLine("\n\nAverage Score for Bowler:{0}");
}
}
Add this
usingstatement:Then you can use:
Simple enough.