Wednesday, 11 December 2013

C++ Menggunakan Struct Menampilkan Nilai


#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
struct nilai
{
int siswa_ke;
char nama[20];
int mid;
int final;
int rata;
};
nilai mhs[10];
for(int i = 0; i <3; i++)
{
 mhs[i].siswa_ke=i+1;
 cout<<"Nama: ";
 cin>>mhs[i].nama;
 cout<<"Input Nilai Mid : ";
 cin>>mhs[i].mid;
 cout<<"Input Nilai Final : ";
 cin>>mhs[i].final;
 mhs[i].rata=(mhs[i].mid+mhs[i].final)/2;
}
 cout<<"---------------------------------------------------------"<<endl;
 cout<<"Siswa Ke  NAMA  MID  FINAL  RATA-RATA"<<endl;
 cout<<"---------------------------------------------------------"<<endl;
for(int i = 0; i <3; i++)
{
 cout<<mhs[i].siswa_ke<<"         ";
 cout<<mhs[i].nama<<"   ";
 cout<<mhs[i].mid<<"     ";
 cout<<mhs[i].final<<"      ";
 cout<<mhs[i].rata<<endl;
}
 cout<<"---------------------------------------------------------";
getch();
}

No comments:

Post a Comment