Skip to content

Instantly share code, notes, and snippets.

@vanloc0301
Created May 11, 2013 21:11
Show Gist options
  • Save vanloc0301/5561438 to your computer and use it in GitHub Desktop.
Save vanloc0301/5561438 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <conio.h>
#include <cstdlib>
#include <ctime>
using namespace std;
int main ()
{
char*ten=new char[100];
string *thongtin=new string[100];
string line;
int *a=new int[100];
ifstream myfile ("data.txt");
int i=1;
int dongcauhoi;
int slch,goicauhoi;
int demdong;
int diem=0;
int socau;
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
thongtin[i]=line;
i++;
}
demdong=i;
myfile.close();
}
else cout << "Unable to open file";
cout<<"-------------Chao mug cac ban den voi tro choi van hoc--------------"<<endl;
cout<< "\t\t moi ban nhap so luong cau hoi de choi :";
srand(time(0));
cin>>slch;
socau=slch;
do {
int goicauhoi=(rand()%(slch+1)) +1;
cout<<endl;
for(int j=goicauhoi-1;j<demdong;j++)
{
dongcauhoi=1+3*j;
break;
}
for(int i=dongcauhoi;i<=demdong;i++)
{
cout<<"cau hoi "<<thongtin[i]<<thongtin[i+1]<<endl;
cout<<"\t nhap cau tra loi :";
fflush(stdin);
gets(ten);
cout<<"\t Dap An :"<<thongtin[i+2]<<endl;
if(thongtin[i+2]==ten)
{
diem++;
cout<<"ban chon dung:"<<endl;
}
break;
}
slch--;
}while(slch>0);
if(diem==socau)
{
cout<<"\t------good-----win-------";
}
return 0;
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment