Ugd9 c 7644
- 1. #include<stdio.h>
#include<conio.h>
#include<windows.h>
float rata_rata(float pt,float ugd,float tgs,float lap);
char huruf(float x);
float rata_rata(float pt,float ugd,float tgs,float lap)
{
float temp,tempe;
tempe=pt+ugd+tgs+lap;
temp=(pt*0.1)+(ugd*0.4)+tgs*0.2+(lap*0.3);
return temp;
}
char huruf(float x)
{
char z;
if(x>=80)
{
z='A';
return z;
}
if(x>=65)
{
z='B';
return z;
}
if(x>=50)
{
z='C';
return z;
}
if(x>=30)
{
z='D';
return z;
}
}
void main ()
{
int pil,nim;
char nama[20];
float pt,ugd,lap,tgs,temp,rerata,x,tempe;
do{
system ("cls");
printf("--------------------n");
printf("1.INPUT DATAn");
printf("2.TAMPIL DATAn");
printf("3.RATA-RATAn");
printf("4.Nilai Akhirn");
printf("0.exitn");
printf("=====================n");
printf("Pilih menu: ");scanf("%d",&pil);
switch(pil)
{
case 1 : fflush(stdin);
- 2. printf("n+> Masukkan Nama: ");scanf("%s",&nama);
do
{
printf("n+> Masukkan NIM: ");scanf("%d",&nim);
}while(nim>=9999 || nim<=1000);
do
{
printf("n+> Masukkan Nilai Pretest:
");scanf("%f",&pt);
}while(pt>100 || pt<0);
do
{
printf("n+> Masukkan Nilai UGD:
");scanf("%f",&ugd);
}while(pt>100 || pt<0);
do
{
printf("n+> Masukkan Nilai Tugas: ");scanf("%f",&tgs);
}while(pt>100 || pt<0);
do
{
printf("n+> Masukkan Nilai Lap:
");scanf("%f",&lap);
}while(pt>100 || pt<0);
printf("nData Berhasil dimasukkan!!");
getch ();
break;
case 2 :
printf("Mahasiswa: %s",strupr(nama));
printf("nNIM : %d",nim);printf(" Mendapatkan
Nilai: n");
printf("tnPretest : %.2f",pt);
printf("tnUnguided : %.2f",ugd);
printf("tnTugas : %.2f",tgs);
printf("tnLaporan : %.2f",lap);
getch ();
break;
case 3 :
printf("Rata-rata dari %d",nim);
printf(" : %.2f",rata_rata(pt,ugd,tgs,lap));
getch ();
break;
case 4 :
printf("Nilai Akhir ialah :
%s",huruf(rata_rata(pt,ugd,tgs,lap))); break;
default: printf("nTerimakasih."); break;
}
}while (pil!=0);
}