Bugs Practice
Complete the following exercises in a new C# project.
Setup
- Define a new method named
Bugs
with return typevoid
that takes no input arguments - Call the
Bugs
method from theMain
method so it runs when the program runs - Copy and paste each of the following code snippets into the body of the
Bugs
method - Fix each of the snippets so they function properly!
Bug 1
Console.WriteLine("Welcome to my program);
Bug 2
Console.WriteLine("This is a good program")
Bug 3
Console.WriteLine("How old are you?");
int age = Console.ReadLine();
int dogAge = age * 7;
Console.WriteLine("You are " + dogAge + " in dog years!");
Bug 4
if (age = 12) {
Console.WriteLine("You are 12!");
}
Bug 5
Console.WriteLine("What is the capital of Ohio?");
string capital = Console.ReadLine();
if (capital == "Columbus") {
Console.WriteLine("You are right");
}
esle
{
Console.WriteLine("You are wrong");
}
Bug 6
int i = 0;
while (i < 10) {
Console.WriteLine(i);
i+;
}
Bug 7
int sum = 0;
for (j = 0; j < 10; j++) {
sum += j;
}
Console.WriteLine("Sum: " + sum);