Selasa, 02 Juni 2015

Script C++ Membuat table dan memberi nilai menggunakan if else

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int nim[10];
char nama[10][10];
int nilai[10];
int i,n,no=1;
cout<<"masukkan jumlah mahasiswa: ";cin>>n;;
for (i=1;i<=n;i++)
{
cout<<"masukkan nim  : ";cin>>nim[i];
cout<<"masukkan nama : ";cin>>nama[i];
cout<<"masukkan nilai: ";cin>>nilai[i];
cout<<"\n";
};
cout<<"jum mahasiswa: "<<n<<endl;
cout<<"\n";
cout<<"|no|\tnim\t|\tnama\t|\tnilai\t|  nilai huruf  |\n";
for (i=1;i<=n;i++)
{
if(nilai[i]>= 80 && nilai[i]<=100){
cout<<"|"<<no++<<" |\t"<<nim[i]<<"\t|\t"<<nama[i]<<"\t|\t"<<nilai[i]<<"\t|\t"<<"A"<<"\t|"<<endl;
}
else if(nilai[i]>=60)
{cout<<"|"<<no++<<" |\t"<<nim[i]<<"\t|\t"<<nama[i]<<"\t|\t"<<nilai[i]<<"\t|\t"<<"B"<<"\t|"<<endl;
}
else{
cout<<"|"<<no++<<" |\t"<<nim[i]<<"\t|\t"<<nama[i]<<"\t|\t"<<nilai[i]<<"\t|\t"<<"C"<<"\t|"<<endl;
}}
cout<<"\n";
getch();
}


Hasil Compile :


0 komentar:

Posting Komentar