Question: Assume that you correct for minor compile-time errors. Given the code for the following game, identify the statements that are true. #include ; using namespace
Assume that you correct for minor compile-time errors. Given the code for the following game, identify the statements that are true.
- #include
; - using namespace std;
- int main() {
- int i = 10, b, tries = 0;
- cout << "Guess the number between 0 and 19?" << endl;
- for(; tries < 4; tries++) {
- cin << b;
- if(i == b) break;
- if(i >= b) cout << "higher" << endl;
- else if (i < b) cout << "lower" << endl
- }
- if(tries == 4)
- cout < "The answer was: " << i << ". Game Over!" << endl;
- else
- cout << "Correct!" << end1;
- return 0;
- }
Select one or more:
a. The program would always run the same if line 15 uses if instead of else if.
b. If we instead assigned i the value of 12 and guessed 10, 15, 13, 12, then the outputs would be lower, higher, lower, Correct!
c. If we instead assigned i the value of 9 and guessed 11, 6, 10, 8, then the outputs would be lower, higher, lower, higher, The answer was: 9. Game Over!
d. If the error on line 14 is not fixed, the output will be wrong.
e. If we instead assigned i the value of 9 and guessed 11, 6, 10, 8, then the outputs would be higher, higher, lower, higher, The answer was: 9. Game Over!
f. If we instead assigned i the value of 12 and guessed 10, 15, 13, 12, then the outputs would be higher, lower, lower, Correct!
g. tries needs to be initialized before the first ; on line line 11 or the output may be undefined.
Assume that you correct for minor compile-time errors. Select the statements that are true.
- #include
- #include
- using namespace std;
- int main() {
- int f = 2;
- double k = -1.2;
- double a = 1.44;
- const float epsilon = 0.000001;
- if(abs(pow(k, f)) - a < epsilon) {
- cout << "Power! ";
- }
- if(pow(k, f+1) == abs(pow(k, f+1))) {
- cout << "More Power! ";
- }
- cout << end1;
- return 0;
- }
Select one or more:
a. The equivalence operator on line 15 should be === to avoid floating point error.
b. The output is Power! More Power!
c. No choice of epsilon will ever catch all floating point rounding errors.
d. Floating point multiplication is inexact and can lead to unexpected errors.
e.The output is Power!.
cout << bar[3] < end1;
Assume that you correct for minor compile-time errors. Select the true statements about the following code.
- #include
- using namespace std;
- int main() {
- int x, y, z;
- cin > x > y > z;
- if(x < y) {
- if(y < z)
- cout << "first < second";
- cout << " and second < third" << endl;
- } else {
- cout << "second <= first and "
- if(x < z)
- cout << "first < third" << endl
- } else {
- cout << "third <= first") << endl;
- }
- return 0;
- }
-
Select one or more:
a. If the input is "2 1 3" then the output will be second <= first and first < third
b. If the input is "2 1 3" then the output will be second <= first and third <= first
c. If the input is "3 1 2" then the output will be second <= first and third <= first
d.If the input is "3 1 2" then the output will be and second < third
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
