Contoh ke 2 untuk program Array 1 Dimensi
#include <iostream.h>#include <conio.h>
#include <stdio.h>
void main(){
char soal[5][100]={"1. sebutkan ","2. jelaskan ","3. terangkan ","4. apa ","5. mengapa "};
char kuncijawaban[5]={'a','b','c','d','a'};
char jawaban[5];
int skor=0,pil,editpil;
kembali:
cout<<"[1].edit soal [2].lanjut soal : ";cin>>pil;
if(pil==1){
ngedit:
cout<<"edit soal ke no : ";cin>>editpil;
cout<<"pertanyaan ke "<<(editpil)<<" : ";gets(soal[editpil-1]);
cout<<"kunci jawaban : ";cin>>kuncijawaban[editpil-1];
char editlagi;
cout<<"edit lagi ?[y][n]";cin>>editlagi;
if(editlagi=='y'){
goto ngedit;
}else{
}
}else{
}
cout<<"\n\ncontoh soal array\n=======================================\n\n";
for(int i=0;i<5;i++){
cout<<soal[i]<<"[a][b][c][d]\n";
cout<<"jawab : ";cin>>jawaban[i];
if(jawaban[i]==kuncijawaban[i]){
skor++;
}else{
}
cout<<endl;
}
cout<<"==================================\n";
cout<<"anda menjawab dengan benar sebanyak : "<<skor<<endl;
cout<<"salah menjawab sebanyak : "<<(sizeof(jawaban)-skor)<<endl<<endl;
char ngulang;
cout<<"lagi[y][n]?";cin>>ngulang;
if(ngulang=='y'){
goto kembali;
}else{
}
getch();
}
Tidak ada komentar:
Posting Komentar