i have written a model program . though my actual program contains another set of questions(the questions i have used here are real easy.)
i have made use of srand and rand funtions
here is my code
everything is working fine.the problem arises when a question repeats itself. what should i do to make sure a question is asked only once?Code:#include<iostream> #include<conio.h> #include <cstdlib> #include <ctime> using namespace std; main() { srand((unsigned)time(0)); int question,score=0; int option1,option2,option3,option4; for(int a=1;a<4;a++) { question=(rand()%4)+1; if(question==1) { cout<<"What is 8+5 "; cin>>option1; if(option1==13) { score++; cout<<"Correct answer"<<endl; cout<<"Score ="<<score<<endl; } else { score--; cout<<"Bad answer"<<endl; cout<<"Score ="<<score<<endl; } } if(question==2) { cout<<"What is 8+5"<<endl; cin>>option1; if(option1==13) { score++; cout<<"Correct answer"<<endl; cout<<"Score ="<<score<<endl; } else { score--; cout<<"Bad answer"<<endl; cout<<"Score ="<<score<<endl; } } if(question==3) { cout<<"What is 8+4"; cin>>option2; if(option2==12) { score++; cout<<"Correct answer"<<endl; cout<<"Score ="<<score<<endl; } else { score--; cout<<"Bad answer"<<endl; cout<<"Score ="<<score<<endl; } } if(question==4) { cout<<"What is 8-5"; cin>>option3; if(option3==3) { score++; cout<<"Correct answer"<<endl; cout<<"Score ="<<score<<endl; } else { score--; cout<<"Bad answer"<<endl; cout<<"Score ="<<score<<endl; } } } getch(); }