Read the question, write C++ on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read a Celsius temperature (it may have decimals) and print it in Fahrenheit.
F = C × 9/5 + 32. Print the result with exactly one digit after the decimal point.
Input. One line: a number.
Output. Fahrenheit to one decimal, e.g. 98.6
Constraints
- Read into a double, not an int.
Examples
Input
37
Output
98.6
Input
100
Output
212.0
Hint
- Read a double so decimals survive: double c; std::cin >> c;
- #include <iomanip>, then std::cout << std::fixed << std::setprecision(1) << value;
Show correct code
Peek only after you have tried. You can still Check your own version.
#include <iostream>
#include <iomanip>
int main() {
double c;
std::cin >> c;
std::cout << std::fixed << std::setprecision(1) << (c * 9 / 5 + 32) << "\n";
return 0;
}
main.cppC++17 · g++ · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.