i am experimenting with counting while and do while loops and what not, and i am having some trouble printing my results, the program description and the code follows
Each of 4 bowlers will enter his or her three bowling scores. Validate the user input in the range of 0 to 300. Include in the prompt the player’s number. (For example, the prompt might be: “Enter score 1 for player #1, score must be between 0 & 300”. Calculate and print the average for each player and the total points for the team.
csharp
namespace Lab3ConsoleMTT
{
class Program
{
static void Main(string[] args)
{
int bowler, scoreNumber, score;
bool isScoreValid, isNumberValid;
int[] scores = new int[4]; // total scores for each bowler
bowler = 1;
while (bowler < 5)
{
scoreNumber=1;
while (scoreNumber < 4)
{
do
{
Console.Write("Enter score {0} for player #{1},
score must be between 0 & 300 : ", scoreNumber, bowler);
isScoreValid=false;
isNumberValid=int.TryParse(Console.ReadLine(),
out score);
if (!isNumberValid) continue; // reinput score
if (score >= 0 && score <=300)
{
scores[bowler - 1] +=score;
scoreNumber++; // can now get next score, if any
isScoreValid=true;
}
}
while (!isScoreValid); // end do
///here i know i have a valid score...i should be totaling up the sum (in order to
calculate the average....
} // end inner while
///Here i am done with a player....I need to calculate and print the average
///I might have to reinitialize some variables to get ready for the next player.
///I will also have to add to totals for the final pin count...
Console.WriteLine();
bowler++; // can now get scores for next bowler,if any
} // end outer while
//here I am done with all players...print the final pin count.
}
}
}
This post has been edited by PsychoCoder: 3 Mar, 2008 - 08:46 AM