top of page
Writer's pictureD A Rosi Arsida Wardani

Temperatur Convertion in C++

Do you want to convert Celcius to any kind of temperature that you like with the C++ program but don't know the exact way to do it? Then, you landed in the right place! In this blog, I will show you how to write a program to convert Celcius to Fahrenheit, Kelvin, and Reaumur.


To make it easier, we will use the switch function. So, here's the code :

#include <iostream>
using namespace std;
main(){
    float c,f,k,r;
    int opt;
    cout<<"\t=================================="<<endl;
    cout<<"\t|| Temperatur Convertion Program ||"<<endl; 
    cout<<"\t=================================="<<endl;
    cout<<"\n";
    cout<<"Option Menu	: "<<endl;
    cout<<"1. Celcius convertion to Fahrenheit"<<endl;
    cout<<"2. Celcius convertion to Kelvin"<<endl;
    cout<<"3. Celcius convertion to Reaumur"<<endl;
    cout<<"==========================================="<<endl;
    cout<<"Input option (1-3) : ";
    cin>>opt;  
    switch (opt){
    case 1:
        cout<<"Input Celcius's value   = ";cin>>c;
            f=(c*9/5)+32;
        cout<<"Fahrenheit's value      = "<<f;
        break;
    case 2:
        cout<<"Input Celcius's value   = ";cin>>c;
            k=273+c;
        cout<<"Kelvin's value 	       = "<<k;
        break;
    case 3:
        cout<<"Input Celcius's value   = ";cin>>c;
            r=4*c/5;
        cout<<"Reaumur's value         = "<<r;
        break;
    default:
        cout<<"ERROR 404"<<endl;
        break;
    }
}

The result will look like this :

- When converting Celcius to Fahrenheit :

- When converting Celcius to Kelvin :

- When converting Celcius to Reamur :

- If we input the wrong option :


Done!

Thank you for visiting my blog!



15 views0 comments

Recent Posts

See All

Comments


Post: Blog2_Post
bottom of page