'F' → Fullscreen
Today you shoot an archery final in a new program named 1-25-archery-final. Your rival has already shot six ends, one arrow each, and their scores are an array. You shoot six of your own — steady, or going for gold — and the program works out who won.
How to read the code blocks. Each task's code block shows your whole program, from line 1, as it should look when that task is finished.
The green lines marked with a + are the ones you add or change for that task — everything else is already in your file. Do not type the + sign.
i + 1.< to <= and run it. Write down how many ends printed before the crash, the exception, and the line number. Then change it back., 10 to the end of the array and run it. Write down what changed — and notice you did not touch the loop. Then take it back out.int[] rival = { 7, 9, 6, 8, 7, 6 };
Console.WriteLine($"Archery final: {rival.Length} ends, one arrow each. Your rival has already shot:");
for (int i = 0; i < rival.Length; i++){ Console.WriteLine($" End {i + 1}: {rival[i]}");}mine is made with new int[rival.Length]: the same number of ends as your rival, every score starting at 0.mine[i]. rival[i] and mine[i] are the same end, because they share i.int[] rival = { 7, 9, 6, 8, 7, 6 };int[] mine = new int[rival.Length];
Console.WriteLine($"Archery final: {rival.Length} ends, one arrow each. Your rival has already shot:");
for (int i = 0; i < rival.Length; i++){ Console.WriteLine($" End {i + 1}: {rival[i]}");}
Console.WriteLine();Console.WriteLine("Your turn. A steady shot scores 6 to 8. Going for gold scores anywhere from 4 to 10.");Console.WriteLine();
for (int i = 0; i < mine.Length; i++){ Console.Write($"End {i + 1} (rival {rival[i]}): steady (1) or go for gold (2)? "); int choice = int.Parse(Console.ReadLine());
if (choice == 2) { mine[i] = Random.Shared.Next(4, 11); } else { mine[i] = Random.Shared.Next(6, 9); }
Console.WriteLine($" You shot {mine[i]}.");}mine[i] > rival[i] compares the same end in both arrays. That needs the index; the values alone would not say which arrow goes with which.int[] rival = { 7, 9, 6, 8, 7, 6 };int[] mine = new int[rival.Length];
Console.WriteLine($"Archery final: {rival.Length} ends, one arrow each. Your rival has already shot:");
for (int i = 0; i < rival.Length; i++){ Console.WriteLine($" End {i + 1}: {rival[i]}");}
Console.WriteLine();Console.WriteLine("Your turn. A steady shot scores 6 to 8. Going for gold scores anywhere from 4 to 10.");Console.WriteLine();
for (int i = 0; i < mine.Length; i++){ Console.Write($"End {i + 1} (rival {rival[i]}): steady (1) or go for gold (2)? "); int choice = int.Parse(Console.ReadLine());
if (choice == 2) { mine[i] = Random.Shared.Next(4, 11); } else { mine[i] = Random.Shared.Next(6, 9); }
Console.WriteLine($" You shot {mine[i]}.");}
int myTotal = 0;int rivalTotal = 0;int endsWon = 0;
for (int i = 0; i < mine.Length; i++){ myTotal = myTotal + mine[i]; rivalTotal = rivalTotal + rival[i];
if (mine[i] > rival[i]) { endsWon = endsWon + 1; }}
Console.WriteLine();Console.WriteLine($"Final score: you {myTotal}, rival {rivalTotal}. You won {endsWon} of {mine.Length} ends.");
if (myTotal > rivalTotal){ Console.WriteLine("You win the final!");}else if (myTotal < rivalTotal){ Console.WriteLine("Your rival takes the final.");}else{ Console.WriteLine("A tie. It goes to a shoot-off.");}best starts at 0 — your first arrow — and moves whenever a later arrow beats mine[best].best + 1 for the end number and mine[best] for the score.int[] rival = { 7, 9, 6, 8, 7, 6 };int[] mine = new int[rival.Length];
Console.WriteLine($"Archery final: {rival.Length} ends, one arrow each. Your rival has already shot:");
for (int i = 0; i < rival.Length; i++){ Console.WriteLine($" End {i + 1}: {rival[i]}");}
Console.WriteLine();Console.WriteLine("Your turn. A steady shot scores 6 to 8. Going for gold scores anywhere from 4 to 10.");Console.WriteLine();
for (int i = 0; i < mine.Length; i++){ Console.Write($"End {i + 1} (rival {rival[i]}): steady (1) or go for gold (2)? "); int choice = int.Parse(Console.ReadLine());
if (choice == 2) { mine[i] = Random.Shared.Next(4, 11); } else { mine[i] = Random.Shared.Next(6, 9); }
Console.WriteLine($" You shot {mine[i]}.");}
int myTotal = 0;int rivalTotal = 0;int endsWon = 0;int best = 0;
for (int i = 0; i < mine.Length; i++){ myTotal = myTotal + mine[i]; rivalTotal = rivalTotal + rival[i];
if (mine[i] > rival[i]) { endsWon = endsWon + 1; }
if (mine[i] > mine[best]) { best = i; }}
Console.WriteLine();Console.WriteLine($"Final score: you {myTotal}, rival {rivalTotal}. You won {endsWon} of {mine.Length} ends.");Console.WriteLine($"Your best arrow was end {best + 1}: {mine[best]}.");
if (myTotal > rivalTotal){ Console.WriteLine("You win the final!");}else if (myTotal < rivalTotal){ Console.WriteLine("Your rival takes the final.");}else{ Console.WriteLine("A tie. It goes to a shoot-off.");}Three changes, one at a time. Write down exactly what happens, and put each one back before the next.
i < mine.Length to i <= mine.Length. Shoot all your ends.int i = 0 to int i = 1 — the way exam lists are numbered. Play a game and add up both totals yourself from the scorecard.new int[rival.Length] to new int[6]. It still works. Now give your rival a seventh end of 10, as in Task 1, and play.Only number 1 crashes. Numbers 2 and 3 give a wrong answer and no error at all. For each, say which total is wrong and by how much. For number 3, say which line the rival's seventh end should have changed.
There is no code block for this task. When it is over, your program is exactly what it was at the end of Task 4.
The exam walks a list two ways. Neither one is a for header: the reference sheet has no counting loop.
for (int i = 0; i < crew.Length; i++){ Console.WriteLine(crew[i]);}FOR EACH name IN crew{ DISPLAY(name)}i ← 1REPEAT LENGTH(crew) TIMES{ DISPLAY(crew[i]) i ← i + 1}FOR EACH name IN crew sets name to each element in turn, first to last. There is no index at all, so it cannot go off the end — and it cannot tell you which position it is on. You will read and write it on the exam; C# has one too, and you will meet it later in the course.
Anything that needs the index — your best end, or matching two lists end by end — is written with REPEAT LENGTH(crew) TIMES and a counter kept by hand, exactly as Activity 1.19 showed.
C# starts at 0 and stops before the length. The exam starts at 1 and repeats LENGTH times. Both visit every element exactly once. Task 5's number 2 is what happens when the exam's habit leaks into C#: int i = 1 quietly skips your first end, and nothing warns you.
One real final from the finished program. Your arrows will be different.
Archery final: 6 ends, one arrow each. Your rival has already shot: End 1: 7 End 2: 9 End 3: 6 End 4: 8 End 5: 7 End 6: 6
Your turn. A steady shot scores 6 to 8. Going for gold scores anywhere from 4 to 10.
End 1 (rival 7): steady (1) or go for gold (2)? 1 [Enter] You shot 6.End 2 (rival 9): steady (1) or go for gold (2)? 2 [Enter] You shot 9.End 3 (rival 6): steady (1) or go for gold (2)? 1 [Enter] You shot 8.End 4 (rival 8): steady (1) or go for gold (2)? 2 [Enter] You shot 4.End 5 (rival 7): steady (1) or go for gold (2)? 1 [Enter] You shot 8.End 6 (rival 6): steady (1) or go for gold (2)? 2 [Enter] You shot 10.
Final score: you 45, rival 43. You won 3 of 6 ends.Your best arrow was end 6: 10.You win the final!Answer the following questions before submitting your work.
i < mine.Length, and what your Task 5 crash showed happens with <=.mine[i] with rival[i], and best keeps an index rather than a score. Explain why both need the position, not just the values.int i = 1 gave a wrong total and no error. Explain where that habit comes from, and why the exam's list starting at 1 still visits every element.Submit four things to the dropbox: