{Mengkonversikan nilai angka menjadi nilai huruf}
Deklarasi
nilai : integer
nilai_huruf : char
read (nilai)
if (nilai > 0) and (nilai < ‘E’ß= 20) then nilai_huruf
else if (nilai > 20) and (nilai < ‘D’ß= 40) then nilai_huruf
else if (nilai > 40) and (nilai < ‘C’ß= 60) then nilai_huruf e
lse if (nilai > 60) and (nilai < ‘B’ß= 80) then nilai_huruf ‘A’ß
else nilai_huruf
endif write (nilai_huruf)
CONTOH PROGRAM
#include <iosteam>
int main() {
int nilai;
char nilai_huruf;
cout << "Masukkan nilai angka = "; cin >> nilai;
if ((nilai > 0) && (nilai <= 20)) nilai_huruf = 'E';
else if ((nilai > 20) && (nilai <= 40)) nilai_huruf = 'D';
else if ((nilai > 40) && (nilai <= 60)) nilai_huruf = 'C';
else if ((nilai > 60) && (nilai <= 80)) nilai_huruf = 'B';
else if ((nilai > 80) && (nilai <=100)) nilai_huruf = 'A';
else nilai_huruf = 'F’;
cout << "Nilai huruf = " << nilai_huruf;
return 0;
}
0 comments:
Post a Comment