Program FUNGSI

Unknown 07.54
PROGRAM FUNGSI :

contoh rumus :
#include<cstdlib>
#include<iostream>

using namespace std;
double hasilp,hasilpp,hasils,hasill;

void persegi(double x)
{
    hasilp=x*x;
}

void persegipanjang(double p,double l)
{
    hasilpp=p*l;
}

void segitiga(double s,double t)
{
    hasils=0.5*s*t;
}

void lingkaran(double j)
{
    hasill=3.14*j*j;
}

int main(int argc, char*argv[])
{
    double a,b,c,d,e,f;
    int pilih;
    char anda;
    do

    {
   
        cout<<"Pilih 1.PERSEGI, 2.PERSEGI PANJANG, 3.SEGITIGA, 4.LINGKARAN=";
        cin>>pilih;
            if(pilih==1)
        {
            cout<<"==Rumus PERSEGI=="<<endl;
            cout<<"sisi=";
            cin>>a;
            persegi(a);
            cout<<"LUAS="<<hasilp<<endl;
        }
   
        else if(pilih==2)
        {
            cout<<"==Rumus PERSEGI PANJANG=="<<endl;
            cout<<"panjang=";cin>>b;
            cout<<"lebar=";cin>>c;
            persegipanjang(b,c);
            cout<<"LUAS="<<hasilpp<<endl;
        }
        else if(pilih==3)
        {
            cout<<"==Rumus SEGITIGA=="<<endl;
            cout<<"alas=";cin>>d;
            cout<<"tinggi=";cin>>e;
            segitiga(d,e);
            cout<<"LUAS="<<hasils<<endl;
        }
        else if(pilih==4)
        {
            cout<<"==Rumus LINGKARAN=="<<endl;
            cout<<"jari-jari=";cin>>f;
            lingkaran(f);
            cout<<"LUAS="<<hasill<<endl;
        }
        else
        {
            cout<<"error"<<endl;
        }
        cout<<"APAKAH ANDA INGIN MENGULANG?(Y/T)";
        cin>>anda;
   
    }while(anda=='y'||anda=='Y');
    system("PAUSE");
    return EXIT_SUCCESS;
}
   

Share this

Related Posts

Previous
Next Post »

Komentar