'F' → Fullscreen
Three glitch reports have come in from the arcade, and you are on bug duty. A player's score went negative, the snack machine kept a dollar and gave nothing back, and the sound meter shows garbage. Each one is a limit of bits. Tasks 1 and 2 go in a program named 2-16-glitch-hunt; Task 3 is a second program, 2-16-sampling.
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.
int.int score = 0;int bonus = 500000000;
for (int round = 1; round <= 6; round++){ score = score + bonus; Console.WriteLine($"Round {round}: score {score}");}:F2 on line 17 so it prints exactly what paid holds, and run it again. Record what dimes 3, 8 and 10 show.if on line 20 chose the else.paid with an int called paidCents, add 10 for each dime, and compare with 100. Change the message to print cents. Then explain why whole numbers cannot have this problem.long score = 0;int bonus = 500000000;
for (int round = 1; round <= 6; round++){ score = score + bonus; Console.WriteLine($"Round {round}: score {score}");}
Console.WriteLine();
double paid = 0;
for (int coin = 1; coin <= 10; coin++){ paid = paid + 0.10; Console.WriteLine($"Dime {coin}: paid ${paid:F2}");}
if (paid >= 1.00){ Console.WriteLine("Here is your snack.");}else{ Console.WriteLine("Please insert more coins.");}Wave plays the part of a microphone: give it a time in seconds and it returns the volume of a sound at that moment. It changes smoothly, so it is analog. Do not change it.ShowSamples(step) measures the wave every step seconds from 0 to 40 and draws each sample as a bar of #, one for every 5 units of volume, then the number. Read the bars down the screen like a graph turned on its side.ShowSamples(20);ShowSamples(5);ShowSamples(2);
void ShowSamples(int step){ Console.WriteLine($"One sample every {step} seconds:");
for (int t = 0; t <= 40; t = t + step) { double level = Wave(t);
for (int k = 0; k < level / 5; k++) { Console.Write("#"); }
Console.WriteLine($" {level:F0}"); }
Console.WriteLine();}
// Wave stands in for a microphone. Do not change it.double Wave(int t){ return 50 + 40 * Math.Sin(t / 5.0);}double version, write bool CloseEnough(double a, double b) that returns true when a - b and b - a are both less than 0.000001. Use it so the machine gives the snack.Doubling 1 sixty-four times, in both languages.
long big = 1;
for (int i = 0; i < 64; i++){ big = big * 2;}
Console.WriteLine(big);big ← 1
REPEAT 64 TIMES{ big ← big * 2}
DISPLAY(big)The C# version overflows, as Doubling(64) did in Activity 2.12. The exam version displays 18446744073709551616, all twenty digits. The College Board says the exam's language stores integers in as much space as they need, limited only by the computer's memory.
This is one of the few places where the exam's language behaves differently from C#, not just looks different. An exam question about a very large number is asking for the arithmetic. It is not testing whether you know C#'s limits. A question about overflow will say the storage has a fixed number of bits.
The C# loop needs i to count, even though the body never uses it. REPEAT 64 TIMES just repeats. When an exam loop does need to know which pass it is on, it keeps its own variable and adds 1 to it.
After the fix in Task 1, the score prints exactly this.
Round 1: score 500000000Round 2: score 1000000000Round 3: score 1500000000Round 4: score 2000000000Round 5: score 2500000000Round 6: score 3000000000And Task 3 prints exactly this.
One sample every 20 seconds:########## 50#### 20################## 90
One sample every 5 seconds:########## 50################# 84################## 86############ 56#### 20### 12######## 39################ 76################## 90
One sample every 2 seconds:########## 50############## 66################ 79################## 87################## 90################## 86################ 77############# 63########## 48####### 32#### 20### 12### 10### 15##### 25######## 39########### 55############## 70################# 82################## 89################## 90Answer the following questions before submitting your work.
Submit four things to the dropbox: