Program Menghitung Grade Nilai Mahasiswa dan Penjualan Minuman dengan If Else dan Switch Case di Dev C++ / Codeblock
Langkah-langkah:
1. Buka software aplikasi Dev C++ atau Codeblock
2. Klik Menu File, pilih New, pilih Project
3. Pilih Console Aplication, pilih Go
4. Pilih C++, Next
5. Beri nama project, lalu Next, kemudian Finish
6. Kemudian ketikkan sintax seperti berikut:
#include <iostream>
#include <stdlib.h>
#include <cstdlib>
#include <math.h>
#include <conio.h>
using namespace std;
int main()
{
int choice;
char pilih;
menu:
cout<<endl;
cout<<" =============================="<<endl;
cout<<" >>>>>>>>>>>> MENU <<<<<<<<<<<<"<<endl;
cout<<" =============================="<<endl<<endl;
cout<<" 1. Nested IF"<<endl;
cout<<" 2. Switch Case"<<endl<<endl;
cout<<" Masukkan Pilihan [1/2] = ";
cin>>choice;
switch(choice)
{
case 1:
system("cls");
int id,uts,uas,tugas, score;
char nama[50], grade, *info;
cout<<endl;
cout<<" Masukkan ID Mahasiswa = ";
cin>>id;
cout<<" Masukkan Nama Mahasiswa = ";
cin>>nama;;
cout<<" Masukkan Nilai UTS = ";
cin>>uts;
cout<<" Masukkan Nilai UAS = ";
cin>>uas;
cout<<" Masukkan Nilai Tugas = ";
cin>>tugas;
//rumus
score=((uts+uas+tugas)/3);
if(score>=100)
{
grade='-';
info="-";
}
else if(score>=80)
{
grade='A';
info="Lulus";
}
else if(score>=70)
{
grade='B';
info="Lulus";
}
else if(score>=60)
{
grade='C';
info="Lulus";
}
else if(score>=50)
{
grade='D';
info="Ulang";
}
else
{
grade='E';
info="Ulang";
}
cout<<endl;
cout<<" Data yang telah anda input adalah sebagai berikut: "<<endl<<endl;
cout<<" ID Mahasiswa = "<<id<<endl;
cout<<" Nama Mahasiswa = "<<nama<<endl;
cout<<" Nilai = "<<score<<endl;
cout<<" Grade = "<<grade<<endl;
cout<<" Keterangan = "<<info<<endl<<endl;
cout<<" Kembali ke Menu [y/t]? = ";
cin>>pilih;
if(pilih=='y'||pilih=='Y')
{
system("cls");
goto menu;
}
else
{
exit (0);
}
break;
case 2:
system("cls");
int choice,hrg,total,jum_pes,disk,bayar;
menu2:
cout<<endl;
cout<<" *************** FRESH ***************"<<endl;
cout<<" 1. Juice"<<endl;
cout<<" 2. Soft Drink"<<endl;
cout<<" 3. Milk Shake"<<endl;
cout<<" 4. Tiramisu"<<endl;
cout<<" 5. Cookies Cream"<<endl<<endl;
cout<<" Pilih Pesanan Anda [1/2/3/4/5] = ";
cin>>choice;
cout<<endl;
switch(choice)
{
case 1:
cout<<" ======================================="<<endl;
cout<<" | No| Fresh Menu | Harga (Rp) |"<<endl;
cout<<" ======================================="<<endl;
cout<<" | 1 | Juice | Rp. 10.000 |"<<endl;
cout<<" | 2 | Soft Drink | Rp. 15.000 |"<<endl;
cout<<" | 3 | Milk Shake | Rp. 20.000 |"<<endl;
cout<<" | 4 | Tiramisu | Rp. 18.000 |"<<endl;
cout<<" | 5 | Cookies Cream | Rp. 16.000 |"<<endl;
cout<<" ======================================="<<endl<<endl;
hrg=10000;
cout<<" Pesanan Anda = Juice"<<endl;
break;
case 2:
cout<<" ======================================="<<endl;
cout<<" | No| Fresh Menu | Harga (Rp) |"<<endl;
cout<<" ======================================="<<endl;
cout<<" | 1 | Juice | Rp. 10.000 |"<<endl;
cout<<" | 2 | Soft Drink | Rp. 15.000 |"<<endl;
cout<<" | 3 | Milk Shake | Rp. 20.000 |"<<endl;
cout<<" | 4 | Tiramisu | Rp. 18.000 |"<<endl;
cout<<" | 5 | Cookies Cream | Rp. 16.000 |"<<endl;
cout<<" ======================================="<<endl<<endl;
hrg=15000;
cout<<" Pesanan Anda = Soft Drink"<<endl;
break;
case 3:
cout<<" ======================================="<<endl;
cout<<" | No| Fresh Menu | Harga (Rp) |"<<endl;
cout<<" ======================================="<<endl;
cout<<" | 1 | Juice | Rp. 10.000 |"<<endl;
cout<<" | 2 | Soft Drink | Rp. 15.000 |"<<endl;
cout<<" | 3 | Milk Shake | Rp. 20.000 |"<<endl;
cout<<" | 4 | Tiramisu | Rp. 18.000 |"<<endl;
cout<<" | 5 | Cookies Cream | Rp. 16.000 |"<<endl;
cout<<" ======================================="<<endl<<endl;
hrg=20000;
cout<<" Pesanan Anda = Milk Shake"<<endl;
break;
case 4:
cout<<" ======================================="<<endl;
cout<<" | No| Fresh Menu | Harga (Rp) |"<<endl;
cout<<" ======================================="<<endl;
cout<<" | 1 | Juice | Rp. 10.000 |"<<endl;
cout<<" | 2 | Soft Drink | Rp. 15.000 |"<<endl;
cout<<" | 3 | Milk Shake | Rp. 20.000 |"<<endl;
cout<<" | 4 | Tiramisu | Rp. 18.000 |"<<endl;
cout<<" | 5 | Cookies Cream | Rp. 16.000 |"<<endl;
cout<<" ======================================="<<endl<<endl;
hrg=18000;
cout<<" Pesanan Anda = Tiramisu"<<endl;
break;
case 5:
cout<<" ======================================="<<endl;
cout<<" | No| Fresh Menu | Harga (Rp) |"<<endl;
cout<<" ======================================="<<endl;
cout<<" | 1 | Juice | Rp. 10.000 |"<<endl;
cout<<" | 2 | Soft Drink | Rp. 15.000 |"<<endl;
cout<<" | 3 | Milk Shake | Rp. 20.000 |"<<endl;
cout<<" | 4 | Tiramisu | Rp. 18.000 |"<<endl;
cout<<" | 5 | Cookies Cream | Rp. 16.000 |"<<endl;
cout<<" ======================================="<<endl<<endl;
hrg=16000;
cout<<" Pesanan Anda = Cookies Cream"<<endl;
break;
default:
cout<<" Pilihan Tidak Tersedia"<<endl;
cout<<" ----------------------"<<endl<<endl;
goto menu2;
break;
}
cout<<" Harga Satuan = "<<hrg<<endl;
cout<<" Jumlah Pesanan = ";
cin>>jum_pes;
//rumus
total=jum_pes*hrg;
if (jum_pes>=3)
{
disk=(total*0.25);
}
else
{
disk=0;
}
bayar=total-disk;
cout<<" Diskon = "<<disk<<" -----> ("<<total<<" - "<<disk<<")"<<endl;
cout<<" Total bayar = "<<bayar<<endl<<endl;
cout<<" Kembali Ke Menu [y/t]? = ";
cin>>pilih;
if(pilih=='y'||pilih=='Y')
{
system("cls");
goto menu;
}
break;
}
return 0;
}
7. Kemudian klik Menu Build, pilih Run / Build and Run
Selesai
Semoga bermanfaat
No comments:
Post a Comment