Group
Introduction to C++
Objective
1. Declare a variable to store the temperature in Celsius.
2. Prompt the user to enter a temperature in Celsius.
3. Use the conversion formula Fahrenheit = (Celsius * 9/5) + 32.
4. Store the result in a second variable.
5. Display the result in Fahrenheit using `cout`.
Convert degrees Celsius to Fahrenheit.
Example C++ Exercise
Show C++ Code
#include <iostream> // Include the iostream library to handle input and output operations
using namespace std; // Use the standard namespace to avoid prefixing std::
// Main function - entry point of the program
int main() {
double celsius, fahrenheit; // Declare variables to store Celsius and Fahrenheit values
// Ask the user to enter temperature in Celsius
cout << "Enter temperature in Celsius: ";
cin >> celsius; // Read the Celsius value from user input
// Apply the formula to convert Celsius to Fahrenheit
fahrenheit = (celsius * 9 / 5) + 32;
// Display the result in Fahrenheit
cout << "Temperature in Fahrenheit: " << fahrenheit << endl;
return 0; // Return 0 to indicate successful program execution
}
Output
Enter temperature in Celsius: 25
Temperature in Fahrenheit: 77