Term
Spot the error in the piece of code:
if (balance <= 0)
cout << "No money.\n";
else (balance >= 0)
cout << "You've got money.\n"; |
|
Definition
if (balance <= 0)
cout << "No money.\n";
else (balance >= 0)
cout << "You've got money.\n";
Else statements do not take arguments.
if (balance <= 0)
cout << "No money.\n";
else
cout << "You've got money.\n";
|
|
|
Term
Spot the error in the code:
if (age < 21)
cout << "You are not old enough to drink.\n\n";
else
cout << "Would you like to buy a drink?\n";
cin >> choice; |
|
Definition
if (age < 21)
cout << "You are not old enough to drink.\n\n";
else
cout << "Would you like to buy a drink?\n";
cin >> choice;
Statements with more than 1 actions require curly braces:
else
{
cout << "Would you like to buy a drink?\n";
cin >> choice;
} |
|
|
Term
|
Definition
|
|
Term
|
Definition
|
|
Term
Describe what this statement is doing.
if (num1 > num2) && (num2 > num3))
{
cout << "num1 is greater than num3.\n";
} |
|
Definition
It is using an "if" statement to verify that "num1" is greater than "num2" and that "num2" is greater than "num3". If these conditions are true the program will output the statement, "num1 is greater than num3."; |
|
|
Term
Identify the error:
switch (grade)
{
case 'A' : cout << "You've received an A.\n";
break;
case 'B' : cout << "You've received a B.\n";
break;
case 'C' : cout << "Your grade is average.\n";
break;
default : cout << "Invalid entry.\n\n";
} |
|
Definition
switch (grade)
{
case 'A' : cout << "You've received an A.\n";
break;
case 'B' : cout << "You've received a B.\n";
break;
case 'C' : cout << "Your grade is average.\n";
break;
default : cout << "Invalid entry.\n\n";
break;
}
"break;" is required after each case, including the default case. |
|
|
Term
How many times will the following output be repeated?
int counter = 1;
int value = 5;
while (counter < value)
{
cout << "Example.\n\n"; <----- Output
counter++;
}
|
|
Definition
4 times.
The variable "counter" starts at 1. At each increment (counter++) counter increases by 1. When the counter reaches 5, it is no longer less than the variable "value".
|
|
|
Term
How many times will the loop iterate?
while (count < 5)
{
cout << "Hello.\n";
} |
|
Definition
Inifinite loop.
while (count < 5)
{
cout << "Hello.\n";
}
Since there is no increment or decrement operator inside the while-loop, the loop will continue forever because "count" will always have a "0" assigned to it. |
|
|
Term
Find the error in the code:
do
{
cout << "#" << count << ".) Hello"\n";
} while (count < 5) |
|
Definition
do
{
cout << "#" << count << ".) Hello"\n";
} while (count < 5);
Do-while loops require a semicolon at the end.
|
|
|
Term
How many times will this loop iterate?
const int SIZE = 5;
for (int i = 0; i < SIZE; i++)
{
cout << i+1 << endl;
} |
|
Definition
5
Because the constant integer "SIZE" is assigned to 5. |
|
|