Skip to main content

✍️ Practice (Easy)

1. Mismatched Sum​

The program below prints 24 instead of 6. Fix it so that it prints 6.

int num1 = 2;
string num2 = "4";

Console.WriteLine(num1 + num2);

2. Integer Division​

The program below is supposed to print 0.5, but it prints 0. Fix it so that it prints 0.5.

double half = 1 / 2;

Console.WriteLine(half);

3. Naming Things​

The program below doesn't compile because of 3 invalid variable names. Rename them so that it runs.

int 1stPlace = 1;
string first name = "Elizabeth";
double total.cost = 20.95;

Console.WriteLine(1stPlace);
Console.WriteLine(first name);
Console.WriteLine(total.cost);

4. Tipping Point​

What is the magic number in the program below? Rewrite the program so that it no longer has one.

double lunchTip = 20.00 * 0.15;
double dinnerTip = 60.00 * 0.15;

Console.WriteLine(lunchTip + dinnerTip);