Sunday, November 29, 2015

C++ - Konversi Suhu

Contoh program C++ mengkonversikan suhu dari Celcius ke Fahrenheit, Kelvin dan Reamur menggunakan SwitchCase.

SOURCE CODE
#include <iostream>
#include <conio.h>
using namespace std;

main(){
    float celcius, hasilfahrenheit, hasilkelvin, hasilreamur;
    int pilih;

    cout << "Masukan suhu dalam celcius : ";
    cin >> celcius;

    cout << endl;
    cout << "1. Fahrenheit" << endl;
    cout << "2. Kelvin" << endl;
    cout << "3. Reamur" << endl;
    cout << "Masukan Pilihan : ";
    cin >> pilih;

    cout << endl;
    switch(pilih){
        case 1 :
            hasilfahrenheit = (celcius*9/5)+32;
            cout << celcius << " Celcius = " << hasilfahrenheit << " Fahrenheit";
            break;
        case 2 :
            hasilkelvin = celcius+273.15;
            cout << celcius << " Celcius = " << hasilkelvin << " Kelvin";
            break;
        case 3 :
            hasilreamur = celcius*4/5;
            cout << celcius << " Celcius = " << hasilreamur << " Reamur";
            break;
        default :
            cout << "Pilihan yg anda masukan salah";
            break;
    }
    cout << endl;
    getch();
    return 0;
}

(Baca juga : C++ - Mengurutkan Angka Terbesar ke Terkecil)

OUTPUT
C++ Konversi Suhu Celcius to Fahrenheit
C++ Konversi Suhu Celcius to Kelvin
C++ Konversi Suhu Celcius to Reamur

Terima kasih
Enjoy your day !



EmoticonEmoticon