Senin, 20 Oktober 2014

contoh program if di C

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<windows.h>
main()
{
int code;
menu:
printf("\nDAFTAR HARGA BUAH DAN SAYUR TI 14 C");
printf("\n===================================");
printf("\n1. Buah-buahan");
printf("\n2. Sayur-sayuran");

printf("\nPilih barang yang akan di beli : ");scanf("%i",&code);
        if(code==1)
        {
            system("cls");
            char buah;
            printf("DAFTAR HARGA BUAH-BUAHAN");
            printf("\n=======================");
            printf("\nA. Semangka");
            printf("\nB. Melon");
            printf("\nC. Durian");
            printf("\nPilih Buah <a-c> : ");fflush(stdin);scanf("%c",&buah);
            if(buah=='A'||buah=='a')
            {
                printf("\nHarga Semangka per kilo Rp.10.000");
            }
            else if (buah=='B' || buah=='b')
            {
                printf("\nHarga Melon per kilo Rp.15.000");
            }
            else
            {
                printf("\nHarga Durian per kilo Rp.20.000");
            }
        }
        else if (code==2)
        {
            system("cls");
            char syr;
            printf("DAFTAR HARGA SAYUR-SAYURAN");
            printf("\n=======================");
            printf("\nA. Sawi");
            printf("\nB. Kangkung");
            printf("\nC. Kol");
            printf("\nPilih Buah <a-c> : ");fflush(stdin);scanf("%c",&syr);
            if(syr=='A'||syr=='a')
            {
                printf("\nHarga Sawi per ikat Rp.5.000");
            }
            else if (syr=='B' || syr=='b')
            {
                printf("\nHarga Kangkung per ikat Rp.4.000");
            }
            else
            {
                printf("\nHarga Kol per satuan Rp.6.000");
            }
        }
        else
        {
            system("cls");
            printf("PILIHAN ANDA TIDAK TERSEDIA, PILIH ULANG");
            goto menu;
        }


getch();
}

Tidak ada komentar:

Posting Komentar