Contoh Penggunaan Fungsi

Contoh penggunaan fungsi di c++ :

#include<iostream.h> #include<conio.h> #include<string.h> float lingkaran (float jari); float segitiga (float alas, float tinggi); void main() { float a, t, j, ll, ls; int menu; char menu2; char cekpassword[80]; char password[]="saya"; do { cout << "Masukan Password : "; cin >>cekpassword; clrscr(); } while(strcmp(password, cekpassword)); menu: cout << "Menu : "<<endl; cout << "1. Menghitung Luas Lingkaran"<<endl; cout << "2. Menghitung Luas Segitiga"<<endl; cout << "Pilihan [1/2] : "; cin >> menu; clrscr(); if (menu==1) { cout << "Menghitung Luas Lingkaran"<<endl; cout << "Jari-jari = "; cin >> j; ll=lingkaran(j); cout << "Luas = "<<ll<<endl; cout << "Mau hitung lagi [y/n]? "; cin >> menu2; clrscr(); if(menu2=='y' || menu2=='Y') { goto menu; } else if(menu2=='n' || menu2=='N' ) { cout << "Selesai"; } }else if (menu==2) { cout << "Menghitung Luas Segitiga"<<endl; cout << "Alas = "; cin >> a; cout << "Tinggi = "; cin >> t; ls=segitiga(a, t); cout << "Luas = "<<ls<<endl; cout << "Mau hitung lagi [y/n]? "; cin >> menu2; clrscr(); if(menu2=='y' || menu2=='Y') { goto menu; } else if(menu2=='n' || menu2=='N' ) { cout << "Selesai"; } } } float lingkaran (float jari) { float ll; ll=3.14*jari*jari; return(ll); } float segitiga (float alas, float tinggi) { float ls; ls=alas*tinggi/2; return(ls); }

One thought on “Contoh Penggunaan Fungsi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s