🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
1. Introduction
Temperature conversion is a fundamental concept in physics and everyday life. Converting between Celsius and Fahrenheit is a common task in various applications. In this post, we'll walk through a C++ program that allows the user to convert temperatures between these two scales.
2. Program Overview
Our program will:
1. Display a menu to the user to choose the type of conversion (Celsius to Fahrenheit or Fahrenheit to Celsius).
2. Prompt the user to enter the temperature in the chosen scale.
3. Perform the conversion.
4. Display the converted temperature to the user.
3. Code Program
#include<iostream>
using namespace std;
int main() {
int choice;
float temp, convertedTemp;
cout << "Choose an option:" << endl;
cout << "1. Convert Celsius to Fahrenheit" << endl;
cout << "2. Convert Fahrenheit to Celsius" << endl;
cin >> choice;
switch(choice) {
case 1:
cout << "Enter temperature in Celsius: ";
cin >> temp;
convertedTemp = (temp * 9/5) + 32;
cout << "Temperature in Fahrenheit: " << convertedTemp << endl;
break;
case 2:
cout << "Enter temperature in Fahrenheit: ";
cin >> temp;
convertedTemp = (temp - 32) * 5/9;
cout << "Temperature in Celsius: " << convertedTemp << endl;
break;
default:
cout << "Invalid choice!" << endl;
}
return 0;
}
Output:
Choose an option: 1. Convert Celsius to Fahrenheit 2. Convert Fahrenheit to Celsius 1 Enter temperature in Celsius: 25 Temperature in Fahrenheit: 77
4. Step By Step Explanation
1. The program displays a menu to the user asking for the type of conversion they'd like to perform.
2. Based on the user's choice, the program then asks for the temperature in the appropriate scale.
3. The conversion is performed using the formulas:
- Celsius to Fahrenheit: (temp * 9/5) + 32- Fahrenheit to Celsius: (temp - 32) * 5/9
4. The converted temperature is then displayed.
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment