Switch Case Pada C++

#include <iostream.h>
#include <conio.h>
void main ()
{
clrscr();
char nama[25], npm[8], alamat[25];
int pil, nilai, a;
cout << ",: MENU :. \n1. Biodata \n2. Input Nilai \n3. Genap-Ganjil \n4. Exit";
cout << "\nMasukkan Pilihan : ";
cin >> pil;
switch (pil)
{
case 1:
clrscr();
cout << "\nInput Nama : ";
cin >> nama;
cout << "\nInput NPM : ";
cin >> npm;
cout << "\nInput Alamat : ";
cin >> alamat;
cout << "\nNama anda "<<nama<<", NPM anda "<<npm<<"\nAlamat anda di "<<alamat;
break;
case 2:
clrscr();
cout << "\nInput Nilai Anda : ";
cin >> nilai;
if ( nilai >=90 && nilai <=100)
cout << "\nNilai anda A";
else if ( nilai >=80 && nilai <=89)
cout << "\nNilai anda B";
else if ( nilai >=70 && nilai <=79)
cout << "\nNilai anda C";
else if ( nilai >=50 && nilai <=69)
cout << "\nNilai anda D";
else
cout << "\nAnda gagal";
break;
case 3:
clrscr();
cout << "\nInput Angka : ";
cin >> a;
if (a%2 == 0) {
cout << "\nBilangan Genap";
} else {
cout << "\nBilangan Ganjil";
}
break;
case 4:
clrscr();
cout << "\nTerimakasih";
break;
default:
cout << "\nPilihan anda salah !!! Pilihan hanya ada 4. Ulangi !!";
break;
}
getch();
}



OutPut :















Tidak ada komentar:

Posting Komentar