Program Konversi Suhu di C++ (IF-ELSE-IF)
Program Konversi Suhu di C++ (IF-ELSE-IF)
Konversi ini akan kita kombinasikan dengan pengunaan statmen logika (jika.....maka.....) penggunaan ini bisanya digunakan untuk menyeleseksi pernyataan dalam penggunaan program di C++. Langsung saja kita ikuti script berikut ://PROGRAM KONVERSI TEMPERATUR
//TUGAS INI DITUJUKAN UNTUK MEMENUHI TUGAS C++
//DIBUAT OLEH NURKANA - 1521099
#include <iostream>
#include <windows.h>
using namespace std;
COORD nurkana;
void gotoxy(int x, int y)
{
nurkana. X = x;
nurkana. Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),nurkana);
}
int main()
{
int pilihan; float cel; float fah; float rea; float kel;
gotoxy(21,5);cout<<"----------------------------------";
gotoxy(21,6);cout<<"PROGRAM KONVERSI TEMPERATUR (SUHU)";
gotoxy(21,7);cout<<"----------------------------------";
gotoxy(21,8);cout<<"[1]. Konversi Celcius";
gotoxy(21,9);cout<<"[2]. Konversi Fahrenheit";
gotoxy(21,10);cout<<"[3]. Konversi Reamur";
gotoxy(21,11);cout<<"[4]. Konversi Kelvin";
gotoxy(21,12);cout<<"---------------------------------";
gotoxy(21,13);cout<<"Ketikan pilihan anda = ";
cin>>pilihan
gotoxy(21,14);cout<<"---------------------------------";
if (pilihan==1)
{
gotoxy(21,15);cout<<"Masukan Besaran Celcius = ";
cin>>c;
gotoxy(21,16);cout<<"-------------------------------";
r=(4*c)/5;
f=((9*c)/5)+32;
k=c+273;
gotoxy(21,17);cout<<"Celcius ke Fahreanheit = ";
cout<<f;
gotoxy(21,18);cout<<"Celcius ke Reamur = ";
cout<<r;
gotoxy(21,19);cout<<"Celcius ke Kelvin = ";
cout<<k;
}
else
if (pilihan==2)
{
gotoxy(21,15);cout<<"Masukan Besaran Fahrenheit = ";
cin>>f;
gotoxy(21,16);cout<<"-------------------------------";
c=((5*f)/9)-32;
r=((4*f)/9)-32;
k=(((5*f)/9)-32)+273
gotoxy(21,17);cout<<"Fahrenheit ke Celcius = ";
cout<<c;
gotoxy(21,18);cout<<"Fahrenheit ke Reamur = ";
cout<<r;
gotoxy(21,19);cout<<"Fahrenheit ke Kelvin = ";
cout<<k;
}
else
if (pilihan==3)
{
gotoxy(21,15);cout<<"Masukan Besaran Reamur = ";
cin>>r;
gotoxy(21,16);cout<<"-------------------------------";
c=(5*r)/4;
f=((9*r)/4)+32;
k=((5*r)/4)+273;
gotoxy(21,17);cout<<"Reamur ke Celcius = ";
cout<<c;
gotoxy(21,18);cout<<"Reamur ke Fahrenheit = ";
cout<<f
gotoxy(21,19);cout<<"Reamur ke Kelvin = ";
cout<<k;
}
else
if (pilihan==4)
{
gotoxy(21,15);cout<<"Masukan Besaran Kelvin = ";
cin>>k;
gotoxy(21,16);cout<<"-------------------------------";
c=k-273;
f=((4*k)/5)-273;
r=(((9*k)/5)-273)+32;
gotoxy(21,17);cout<<"Kelvin ke Celcius = ";
cout<<c;
gotoxy(21,18);cout<<"Kelvin ke Fahrenheit = ";
cout<<f;
gotoxy(21,19);cout<<"Kelvin ke Reamur = ";
cout<<r;
}
else
{
gotoxy(21,17);cout<<"Maaf pilihan tersedia hanya 1-4 !";
}
gotoxy(21,20);system ("pause");
return 0;
}
maka, kita dapatkan outputnya seperti ini :