0

I am trying to display an array which by itself is no issue. However, I want to add an If statement, so that if the current iteration of the score[] array that is being displayed is equal to 300 then it will put a * after it. Something like 300*

Also the array needs to display highest to lowest which I am doing by reversing the display at the moment it is in the array as lowest to highest. I was thinking about using a swap to reverse the order but if I don't have to then I would like to solve it this way.

So far I am getting

400
332
300*
300

or in another way I tried, I got

0
0
300*
300
250 
221

I am just having issue with display and output.

static void Output(int iteration, int[] score, string[] player, double average)
    {   //opening output 
        Console.WriteLine("\n\t****** OUTPUT ******");
        Console.WriteLine("\nScores for this game.\n");

        if (score[iteration - 1] == 300)
        {
            Console.WriteLine("{0} score was {1}*", player[iteration - 1], score[iteration - 1]);
        }

        for (int i = iteration; i <= MAX_SIZE_ARRAY; i--)
        {             
                //iterates through the loop to display all the players name then score
                Console.WriteLine("{0} score was {1}", player[i], score[i]);
        }
        //displays high, low, and average score
        Console.WriteLine("\nThe high score was {0} with {1} points", player[iteration - 1], score[iteration - 1]);
        Console.WriteLine("The low score was {0} with {1} points", player[0], score[0]);
        Console.WriteLine("The team average score was {0}", average);

    }
}
}
3
  • Do you just need to move your if statement inside the for loop? Commented Jul 15, 2012 at 23:35
  • I did try that but it gave undesired results also Commented Jul 15, 2012 at 23:37
  • Can you provide a sample of the data coming in? Also in your for loop does it need to be i > 0? Commented Jul 15, 2012 at 23:44

2 Answers 2

2

Moving the if statement inside the loop should work:

for (int i = iteration; i <= MAX_SIZE_ARRAY; i--)
 {             
   //iterates through the loop to display all the players name then score
   if (score[iteration - 1] == 300)
     Console.WriteLine("{0} score was {1}*", player[iteration - 1],                                  score[iteration - 1]);
   else
     Console.WriteLine("{0} score was {1}", player[i], score[i]);
 }

My guess is this a school assignment to make a bowling scoring system? One suggestion would be to link player names with their scores by using a list or array of KeyValuePair, Tuple, or your own Struct definition rather than two separate arrays. Having them separate will lead to issues where they wont match up due to a bug. (removed from one and not the other, sorting changes in one, etc.)

Sign up to request clarification or add additional context in comments.

Comments

0

check score[i] == 300 inside the loop:

for (int i = iteration; i <= MAX_SIZE_ARRAY; i--)
 {             
   if (score[i] == 300)
     Console.WriteLine("{0} score was {1}*", player[i], score[i]);
   else
     Console.WriteLine("{0} score was {1}", player[i], score[i]);
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.