STRUKTUR KONTROL PADA C++, MEMBUAT NILAI SISWA MENGGUNAKAN SWITCH
Untuk 1 Kondisi 2 Syarat :
---------------------------------------------------------------------------------
nilai = 80
kehadiran = 50
if ((kondisi) && (kondisi))
{
statment 1;
statment 1;
}
else if (kondisi 2)
statment 2;
else
statment 3;
----------------------------------------------------------------------------------
Untuk If mempunyai 2 kondisi
----------------------------------------------------------------------------------
if (kondisi 1)
statment;
else if
statment;
else
statment;
----------------------------------------------------------------------------------
Membuat Nilai_siswa dengan mengguanakan Switch !!
----------------------------------------------------------------------------------------------------------------------------
#include <conio.h>
#include <iostream.h>
#include <stdio.h>
void main()
{
char nama[30], kelas[2];
int hadir, uts, uas;
float jml;
long int grade;
cout<<"Nama : "; cin>>nama;
cout<<"Kelas : "; cin>>kelas;
cout<<"\n";
cout<<"Nilai";
cout<<"------------------------------------------------\n";
cout<<"Kehadiran : "; cin>>hadir;
cout<<"UTS : "; cin>>uts;
cout<<"UAS : "; cin>>uas;
cout<<"------------------------------------------------\n";
jml = (hadir+uts+uas) / 3;
cout<<"Jumlah : "<<jml<<endl;
cout<<"------------------------------------------------\n";
grade = jml*10;
switch (grade/10)
{
case 80:
case 81:
case 82:
case 83:
case 84:
case 85:
case 86:
case 87:
case 88:
case 89:
case 90:
case 91:
case 92:
case 93:
case 94:
case 95:
case 96:
case 97:
case 98:
case 99:
case 100:
cout<<"Grade : A "<<endl;
break;
case 75:
case 76:
case 77:
case 78:
case 79:
cout<<"Grade : B "<<endl;
break;
case 65:
case 66:
case 67:
case 68:
case 69:
cout<<"Grade : C "<<endl;
break;
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
case 58:
case 59:
cout<<"Grade : D "<<endl;
break;
default;
cout<<"Grade : E "<<endl;
}
getch();
}
-----------------------------------------------------------------------------------------------------------------------------
Atau yang lebih sederhana
-----------------------------------------------------------------------------------------------------------------------------
#include <conio.h>
#include <iostream.h>
#include <stdio.h>
void main()
{
char nama[30], kelas[2];
int hadir, uts, uas;
float jml;
long int grade;
cout<<"Nama : "; cin>>nama;
cout<<"Kelas : "; cin>>kelas;
cout<<"\n";
cout<<"Nilai";
cout<<"------------------------------------------------\n";
cout<<"Kehadiran : "; cin>>hadir;
cout<<"UTS : "; cin>>uts;
cout<<"UAS : "; cin>>uas;
cout<<"------------------------------------------------\n";
jml = (hadir+uts+uas) / 3;
cout<<"Jumlah : "<<jml<<endl;
cout<<"------------------------------------------------\n";
grade = jml*10;
switch (grade/10)
{
case 80..100:
cout<<"Grade : A "<<endl;
break;
case 75..79:
cout<<"Grade : B "<<endl;
break;
case 65..69:
cout<<"Grade : C "<<endl;
break;
case 50..59:
cout<<"Grade : D "<<endl;
break;
default;
cout<<"Grade : E "<<endl;
}
getch();
}
-----------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------
nilai = 80
kehadiran = 50
if ((kondisi) && (kondisi))
{
statment 1;
statment 1;
}
else if (kondisi 2)
statment 2;
else
statment 3;
----------------------------------------------------------------------------------
Untuk If mempunyai 2 kondisi
----------------------------------------------------------------------------------
if (kondisi 1)
statment;
else if
statment;
else
statment;
----------------------------------------------------------------------------------
Membuat Nilai_siswa dengan mengguanakan Switch !!
----------------------------------------------------------------------------------------------------------------------------
#include <conio.h>
#include <iostream.h>
#include <stdio.h>
void main()
{
char nama[30], kelas[2];
int hadir, uts, uas;
float jml;
long int grade;
cout<<"Nama : "; cin>>nama;
cout<<"Kelas : "; cin>>kelas;
cout<<"\n";
cout<<"Nilai";
cout<<"------------------------------------------------\n";
cout<<"Kehadiran : "; cin>>hadir;
cout<<"UTS : "; cin>>uts;
cout<<"UAS : "; cin>>uas;
cout<<"------------------------------------------------\n";
jml = (hadir+uts+uas) / 3;
cout<<"Jumlah : "<<jml<<endl;
cout<<"------------------------------------------------\n";
grade = jml*10;
switch (grade/10)
{
case 80:
case 81:
case 82:
case 83:
case 84:
case 85:
case 86:
case 87:
case 88:
case 89:
case 90:
case 91:
case 92:
case 93:
case 94:
case 95:
case 96:
case 97:
case 98:
case 99:
case 100:
cout<<"Grade : A "<<endl;
break;
case 75:
case 76:
case 77:
case 78:
case 79:
cout<<"Grade : B "<<endl;
break;
case 65:
case 66:
case 67:
case 68:
case 69:
cout<<"Grade : C "<<endl;
break;
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
case 58:
case 59:
cout<<"Grade : D "<<endl;
break;
default;
cout<<"Grade : E "<<endl;
}
getch();
}
-----------------------------------------------------------------------------------------------------------------------------
Atau yang lebih sederhana
-----------------------------------------------------------------------------------------------------------------------------
#include <conio.h>
#include <iostream.h>
#include <stdio.h>
void main()
{
char nama[30], kelas[2];
int hadir, uts, uas;
float jml;
long int grade;
cout<<"Nama : "; cin>>nama;
cout<<"Kelas : "; cin>>kelas;
cout<<"\n";
cout<<"Nilai";
cout<<"------------------------------------------------\n";
cout<<"Kehadiran : "; cin>>hadir;
cout<<"UTS : "; cin>>uts;
cout<<"UAS : "; cin>>uas;
cout<<"------------------------------------------------\n";
jml = (hadir+uts+uas) / 3;
cout<<"Jumlah : "<<jml<<endl;
cout<<"------------------------------------------------\n";
grade = jml*10;
switch (grade/10)
{
case 80..100:
cout<<"Grade : A "<<endl;
break;
case 75..79:
cout<<"Grade : B "<<endl;
break;
case 65..69:
cout<<"Grade : C "<<endl;
break;
case 50..59:
cout<<"Grade : D "<<endl;
break;
default;
cout<<"Grade : E "<<endl;
}
getch();
}
-----------------------------------------------------------------------------------------------------------------------------
Comments
Post a Comment