I am creating a simple 5 questions quiz program. Now, I want questions to appear randomly and not repeat but I just can't figure this out. here's the code:
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main()
{
int p,sum=0,i,h,temp;
char ch;
cout<<"1: Quaid e azam was born in the year?:"<<endl;
cout<<"(a) 1876 \t (b) 1877"<<endl;
cin>>ch;
if (ch=='a')
{
sum=sum+1;
cout<<"Correct"<<endl;
cout<<"Score is: \t"<<sum<<endl;
}
else
cout<<"Incorrect" <<endl;
cout<<"2: Messi won 5 ballondor?:"<<endl;
cout<<"(a) Yes \t (b) No"<<endl;
cin>>ch;
if (ch=='a')
{
sum=sum+1;
cout<<"correct"<<endl;
cout<<"Score is: \t"<<sum<<endl;
}
else
cout<<"Incorrect"<<endl;
cout<<"3: Is Islamabad is the capital of Pak?:"<<endl;
cout<<"(a) Yes \t (b) No"<<endl;
cin>>ch;
if (ch=='a')
{
sum=sum+1;
cout<<"correct"<<endl;
cout<<"Score is: \t"<<sum<<endl;
}
else
cout<<"Incorrect"<<endl;
cout<<"4: Is Ronaldo is better than Messi?:"<<endl;
cout<<"(a) No \t (b) Yes"<<endl;
cin>>ch;
if (ch=='a')
{
sum=sum+1;
cout<<"correct"<<endl;
cout<<"Score is: \t"<<sum<<endl;
}
else
cout<<"Incorrect"<<endl;
cout<<"5: Is Barcelona a much complete team with Messi?:"<<endl;
cout<<"(a) Yes \t (b) No"<<endl;
cin>>ch;
if (ch=='a')
{
sum=sum+1;
cout<<"correct"<<endl;
cout<<"Score is: \t"<<sum<<endl;
}
else
cout<<"Incorrect"<<endl;
cout<<"Your total score is: \t"<<sum<<endl;
}
Now, I know i have to use rand function but how do I implement these questions in that function? I'm sorry if this is the wrong place to ask this question. Thanks.
Aucun commentaire:
Enregistrer un commentaire