Starting from:
$30

$24

Lab 3 Problems Solution

This lab contains three questions.




Q1. Predict the outputs of the following program.(Before running it). Then run the code and check if your answers are correct.




```c++

#include <iostream

using namespace std;




int main() {

if (12 == 11 || 8 == 8)

cout << "condition is true" << endl;

else

cout << "condition is false" << endl;




if (!false && true)

cout << "aaa" << endl;




if (9 < 12)

cout << "bbb" << endl;

else if (9 12)

cout << "ccc" << endl;

else

cout << "ddd" << endl;




if (9 12) {

if (9 < 17)

cout << "eee" << endl;

}

else

cout << "fff" << endl;

}

```




---




Q2. Write a program to do the following:




- ask the user to enter his/her salary.

- if the salary is less than 5, print "I do not believe you." and exit the program.

- if the salary is between 1000 and 2000, print "We are almost the same."

- if the salary is even number, print "That is an even salary."




---




Bonus. Write a program to do the following:




- ask the user "Can you guess my age? You have 3 chances."(you may hardcode an age of your choice into your program).

- if the user guesses correctly, print "Congratulations!" and exit the program.

- if the user runs out of guesses, print "You failed.

More products