Program menghitung luas, keliling & diameter lingkaran ini menggunakan prosedur void & switch case. Script yang disusun cukup panjang namun masih bisa disederhanakan lagi. Berikut scriptnya :
#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;
float luas(float jari){
return jari*jari*3.14;
}
float keliling(float jari){
return 2*3.14*jari;
}
float diameter(float jari){
return jari*2;
}
int main()
{
menu:
system("cls");
int masukan;
char pil;
float jari;
do
{
cout << "==================================" << endl;
cout << " MENU " << endl;
cout << "1. Hitung Luas Lingkaran " << endl;
cout << "2. Hitung Keliling Lingkaran " << endl;
cout << "3. Hitung Diameter Lingkaran " << endl;
cout << "4. Keluar" << endl;
cout << "==================================" << endl;
cout << "Masukkan pilihan : ";cin>>masukan;
system("cls");
if (masukan == 1 || masukan == 2 || masukan == 3 || masukan == 4) break;
else (cout << " Maaf pilihan anda tidak tersedia!" ) << endl;
}
while (masukan != 4);
switch (masukan)
{
case 1:
cout << "==================================" << endl;
cout << " LUAS LINGKARAN " << endl;
cout << "==================================" << endl;
cout << "Masukkan Nilai Jari - Jari : "; cin >> jari;
cout << "Luas Lingkaran : "<< luas (jari);
cout << "\nKembali ke Menu (Y/N)? : ";
cin >> pil;
if (pil=='y'||pil=='Y')
{
goto menu;
}
else if (pil=='n'||pil=='N')
{
return 0;
}
else
{
cout << "INPUT Y atau N saja !" << endl;
}
break;
case 2:
cout << "==================================" << endl;
cout << " KELILING LINGKARAN " << endl;
cout << "==================================" << endl;
cout << "Masukkan Nilai Jari - Jari : "; cin >> jari;
cout << "Keliling Lingkaran : "<< keliling (jari);
cout << "\nKembali ke Menu (Y/N)? : ";
cin >> pil;
if (pil=='y'||pil=='Y')
{
goto menu;
}
else if (pil=='n'||pil=='N')
{
return 0;
}
else
{
cout << "INPUT Y atau N saja !" << endl;
}
break;
case 3:
cout << "==================================" << endl;
cout << " DIAMETER LINGKARAN " << endl;
cout << "==================================" << endl;
cout << "Masukkan Nilai Jari - Jari : "; cin >> jari;
cout << "Diameter Lingkaran : "<< diameter (jari);
cout << "\nKembali ke Menu (Y/N)? : ";
cin >> pil;
if (pil=='y'||pil=='Y')
{
goto menu;
}
else if (pil=='n'||pil=='N')
{
return 0;
}
else
{
cout << "INPUT Y atau N saja !" << endl;
}
break;
case 4:
return 0;
}
system("pause");
cout << "\nKembali ke Menu (Y/N)? : ";
cin >> pil;
if (pil=='y'||pil=='Y')
{
goto menu;
}
else if (pil=='n'||pil=='N')
{
return 0;
}
else
{
cout << "INPUT Y atau N saja !" << endl;
}
return 0;
}
#include <math.h>
#include <stdlib.h>
using namespace std;
float luas(float jari){
return jari*jari*3.14;
}
float keliling(float jari){
return 2*3.14*jari;
}
float diameter(float jari){
return jari*2;
}
int main()
{
menu:
system("cls");
int masukan;
char pil;
float jari;
do
{
cout << "==================================" << endl;
cout << " MENU " << endl;
cout << "1. Hitung Luas Lingkaran " << endl;
cout << "2. Hitung Keliling Lingkaran " << endl;
cout << "3. Hitung Diameter Lingkaran " << endl;
cout << "4. Keluar" << endl;
cout << "==================================" << endl;
cout << "Masukkan pilihan : ";cin>>masukan;
system("cls");
if (masukan == 1 || masukan == 2 || masukan == 3 || masukan == 4) break;
else (cout << " Maaf pilihan anda tidak tersedia!" ) << endl;
}
while (masukan != 4);
switch (masukan)
{
case 1:
cout << "==================================" << endl;
cout << " LUAS LINGKARAN " << endl;
cout << "==================================" << endl;
cout << "Masukkan Nilai Jari - Jari : "; cin >> jari;
cout << "Luas Lingkaran : "<< luas (jari);
cout << "\nKembali ke Menu (Y/N)? : ";
cin >> pil;
if (pil=='y'||pil=='Y')
{
goto menu;
}
else if (pil=='n'||pil=='N')
{
return 0;
}
else
{
cout << "INPUT Y atau N saja !" << endl;
}
break;
case 2:
cout << "==================================" << endl;
cout << " KELILING LINGKARAN " << endl;
cout << "==================================" << endl;
cout << "Masukkan Nilai Jari - Jari : "; cin >> jari;
cout << "Keliling Lingkaran : "<< keliling (jari);
cout << "\nKembali ke Menu (Y/N)? : ";
cin >> pil;
if (pil=='y'||pil=='Y')
{
goto menu;
}
else if (pil=='n'||pil=='N')
{
return 0;
}
else
{
cout << "INPUT Y atau N saja !" << endl;
}
break;
case 3:
cout << "==================================" << endl;
cout << " DIAMETER LINGKARAN " << endl;
cout << "==================================" << endl;
cout << "Masukkan Nilai Jari - Jari : "; cin >> jari;
cout << "Diameter Lingkaran : "<< diameter (jari);
cout << "\nKembali ke Menu (Y/N)? : ";
cin >> pil;
if (pil=='y'||pil=='Y')
{
goto menu;
}
else if (pil=='n'||pil=='N')
{
return 0;
}
else
{
cout << "INPUT Y atau N saja !" << endl;
}
break;
case 4:
return 0;
}
system("pause");
cout << "\nKembali ke Menu (Y/N)? : ";
cin >> pil;
if (pil=='y'||pil=='Y')
{
goto menu;
}
else if (pil=='n'||pil=='N')
{
return 0;
}
else
{
cout << "INPUT Y atau N saja !" << endl;
}
return 0;
}
Jika ada script yang salah segera laporkan, terima kasih & semoga bermanfaat
Thanks for reading & sharing RZDev: Belajar Programming!
0 comments:
Post a Comment