CLICK HERE

Thursday, 5 January 2012

Contoh C++ Programming


#include <stdio.h>

void main (void){
                int pilih;
                                int minit;
                float jam,
                                  kaki, meter,
                                  fahrenheit, celcius;
                do{
                printf("\n\t\t PERTUKARAN UNIT\n");
                printf("\t\t ===============\n");
                printf("\t1. Masa: minit-> jam\n");
                printf("\t2. Jarak: kaki->meter\n");
                printf("\t3. Suhu: Fahrenheit->Celcius\n");
                printf("\t4. Tamat\n");
                printf("\tPilihan:");
                scanf("%d",&pilih);

                switch (pilih) {
                case 1:
                                printf ("Input masa dalam minit:");
                                scanf("%d",&minit);
                                jam=(float) minit/60;
                                break;
                case 2:
                                printf ("Input jarak dalam kaki:");
                                scanf("%f",&kaki);
                                meter=(float) kaki*0.3048;
                                break;
                case 3:
                                printf ("Input suhu dalam fahrenheit:");
                                scanf("%f",&fahrenheit);
                                celcius=(float) (5.0/9.0)*(fahrenheit-32);
                                break;
                case 4: break;
                default : printf ("Pilihan tidak sah\n");
                }

                switch (pilih){
                case 1 : printf ("%d minit = %.2f jam\n",minit,jam);
                                break;
                case 2 : printf ("%.2f kaki=%.4f meter\n",kaki, meter);
                                break;
                case 3 : printf ("%.2f Fahrenheit=%.2f Celcius\n",fahrenheit,celcius);
                                break;
                }
                } while (pilih !=4);
}

No comments:

Post a Comment