Rabu, 24 April 2013

Konversi Nilai Menjadi Huruf Menggunakan IF dan CASE



Menggunakan IF ini scripnya :

#include

#include

main()

{

int NILAI;

clrscr();

cout<<"KONVERSI NILAI MENJADI HURUF\n";

cout<<"\n-----------------------------------\n";

cout<<"Masukkan Angka Anda =";cin>>NILAI;

if (NILAI<=39)

{

cout<<"E";

}

else

{

if (NILAI>=40 && NILAI<=55)

{

cout<<"D";

}

else

{

if (NILAI>=56 && NILAI<=64)

{

cout<<"C";

}

else

{

if (NILAI>=65 && NILAI<=79)

{

cout<<"B";

}

else

{

if (NILAI>=80 && NILAI<=100)

{

cout<<"A";

}

else

{

cout<<"I";

}

}

}

}

}

getch();

}


Tampilan Hasil :











Menggunakan CASE Ini scripnya :

# include

# include

main()

{

int NILAI;

clrscr();

cout<<"\n============================================\n";

cout<<"Kode Range Nilai\n";

cout<<"\n============================================\n";

cout<<" 1 00-39\n";

cout<<" 2 40-55\n";

cout<<" 3 56-64\n";

cout<<" 4 65-79\n";

cout<<" 5 80-100\n";

cout<<"\n-------------------------------------------\n";

cout<<"Silahkan pilih kode dari nilai anda =";cin>>NILAI;

switch(NILAI)

{

case 1:

cout<<"E";

break;


case 2:

cout<<"D";

break;

case 3:

cout<<"C";

break;


case 4:

cout<<"B";

break;


case 5:

cout<<"A";

break;


default:

cout<<"Invalid";

break;

}

getch();

}


Tampilan Hasil




:




Tidak ada komentar:

Posting Komentar