Creating Expressions and Statements 97
4
Quiz ..................................................................................................................
- What is an expression?
- Is x = 5 + 7 an expression? What is its value?
- What is the value of 201 / 4?
- What is the value of 201 % 4?
- If myAge,a, and bare all intvariables, what are their values after
myAge = 39;
a = myAge++;
b = ++myAge; - What is the value of 8+2*3?
- What is the difference between if(x = 3)and if(x == 3)?
- Do the following values evaluate true or false?
a.^0
b. 1
c. –1
d.x = 0
e. x == 0 // assume that x has the value of 0
Exercises ..........................................................................................................
- Write a single ifstatement that examines two integer variables and changes the
larger to the smaller, using only one elseclause. - Examine the following program. Imagine entering three numbers, and write what
output you expect.
1: #include
2: using namespace std;
3: int main()
4: {
5: int a, b, c;
6: cout << “Please enter three numbers\n”;
7: cout << “a: “;
8: cin >> a;
9: cout << “\nb: “;
10: cin >> b;
11: cout << “\nc: “;
12: cin >> c;
13:
14: if (c = (a-b))
15: cout << “a: “ << a << “ minus b: “ << b <<
16: _” equals c: “ << c;