Tuesday, October 20, 2015

Filled Under:

Contoh program nested if c# ( console )



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            double harga,tot,jum;
            string cust,paket,lagi;
            Console.WriteLine(" Restoran"
                + "\n ======================"
                + "\n Menu :"
                + "\n a) Paket 1 .... RP 20.000"
                + "\n b) Paket 2 .... RP 25.000"
                + "\n c) Paket 3 .... RP 25.000"
                + "\n ======================"
                + "\n\n Form Pesanan"
                + "\n ----------------------");
            x:
            Console.Write(" Jenis Customer [M/N] : ");
            cust = Console.ReadLine().ToUpper();
            if(cust == "M")
            {
                ax:
                Console.Write(" Pilih Paket : ");
                paket = Console.ReadLine();
                if (paket == "1") 
                {
                    harga = 20000;
                }
                else if (paket == "2")
                {
                    harga = 25000;
                }
                else if (paket == "3")
                {
                    harga = 30000;
                }
                else
                {
                    goto ax;
                }
                Console.Write(" Jumlah Pesan = ");
                jum = Convert.ToDouble(Console.ReadLine());
                jum = jum * harga;
                Console.WriteLine("=================================");
                Console.WriteLine("     Sub Total = " + jum);
                Console.WriteLine("     Diskon    = 20%");
                tot = jum - (jum * 20 / 100);
                Console.WriteLine("     Total     = RP." + tot);
            }
            else if (cust == "N")
            {
                ax:
                Console.Write(" Pilih Paket : ");
                paket = Console.ReadLine();
                if (paket == "1")
                {
                    harga = 20000;
                }
                else if (paket == "2")
                {
                    harga = 25000;
                }
                else if (paket == "3")
                {
                    harga = 30000;
                }
                else
                {
                    goto ax;
                }
                Console.Write(" Jumlah Pesan = ");
                jum = Convert.ToDouble(Console.ReadLine());
                jum = jum * harga;
                Console.WriteLine("=================================");
                Console.WriteLine("     Sub Total = " + jum);
                Console.WriteLine("     Diskon    = 10%");
                tot = jum - (jum * 10 / 100);
                Console.WriteLine("     Total     = RP." + tot);
            }
            else
            {
                goto x;
            }
            Console.Write("Ingin Isi Lagi [Y/N] : ");
            lagi = Console.ReadLine().ToUpper();
            if (lagi == "Y")
            {
                Console.Clear();
                goto x;
            }
            else 
            {
                Console.Write("Press Enter To Exit : "); Console.ReadKey();
            }
        }
    }
}


Ditulis oleh

Deskripsi diri belum ditambahkan :) _______________________________________________________________

0 comments:

Post a Comment

crd bsi