Checkpoint 3.2.1.
In the lab, we measured a temperature of 7.99999999 degrees C, using an extremely precise measuring device. Now we are writing a program to perform some calculations with our data. Consider the following C++ code.
int main() {
double temp = 7.99999999;
int roundedTemp = int(temp);
cout << roundedTemp;
}
What is the value of roundedTemp?
- temp
- This is the name of a variable. Only the value of a variable will print with cout.
- 8
- Remember that converting to an integer always rounds down.
- 7
- Correct!
- 8.0
- This is not an integer data type, and it’s not the right number.
- 7.0
- This is not an integer data type.