1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
//Quiz.cpp, (c) 2008 QWERTYman (real name withheld)
#include <iostream>
#include <fac.h>
#include <cstdlib>
#include <ctime>
using namespace std;
int one, two, sol;
int wrong = 0;
int right = 0;
void add();
void sub();
void mult();
void div();
void avg();
int main()
{
extern int right;
int asmd;
char startag;
start:
clearer();
for(int i = 0; i < 10; i++){
srand( (unsigned)time(0) );
asmd = (rand()%5);
if(asmd == 0)
add();
else if(asmd == 1)
sub();
else if(asmd == 2)
mult();
else if(asmd == 3)
div();
else
avg();}
cin.get();
cout << "You got " << right << " right, and " << wrong << " wrong.\n";
do{
cout << "Restart? [y/n] ";
cin >> startag;
if(startag == 'y' || startag == 'Y')
goto start;
else
break;
}while(true);
cin.get();
return 0;
}
void add(){
extern int right;
srand( (unsigned)time(0) );
one = (rand()%999) + 1;
two = (rand()%999) + 1;
cout << "Problem " << wrong + right + 1 << ": " << one << " + " << two << " = ";
cin >> sol;
if(sol == one+two){
right++;
cout << "Correct!\n";}
else{
wrong++;
cout << "Sorry, the answer was " << one+two << ".\n";}
}
void sub(){
extern int right;
srand( (unsigned)time(0) );
one = (rand()%999) + 1;
two = (rand()%999) + 1;
if(one > two){
cout << "Problem " << wrong + right + 1 << ": " << one << " - " << two << " = ";
cin >> sol;
if(sol == one-two){
right++;
cout << "Correct!\n";}
else{
wrong++;
cout << "Sorry, the answer was " << one-two << ".\n";}}
else{
cout << "Problem " << wrong + right + 1 << ": " << two << " - " << one << " = ";
cin >> sol;
if(sol == two-one){
right++;
cout << "Correct!\n";}
else{
wrong++;
cout << "Sorry, the answer was" << two-one << ".\n";}}
}
void mult(){
extern int right;
srand( (unsigned)time(0) );
one = (rand()%50) + 1;
two = (rand()%50) + 1;
cout << "Problem " << wrong + right + 1 << ": " << one << " * " << two << " = ";
cin >> sol;
if(sol == one*two){
right++;
cout << "Correct!\n";}
else{
wrong++;
cout << "Sorry, the answer was " << one*two << ".\n";}
}
void div(){
extern int right;
srand( (unsigned)time(0) );
do{
one = (rand()%999) + 1;
two = (rand()%99) + 2;
}while(one%two != 0);
cout << "Problem " << wrong+right+1 << ": " << one << " / " << two << " = ";
cin >> sol;
if(sol == one/two){
right++;
cout << "Correct!\n";}
else{
wrong++;
cout << "Sorry, the answer was " << one+two << ".\n";}
}
void avg(){
extern int right;
srand( (unsigned)time(0) );
one = (rand()%100) + 1;
two = (rand()%100) + 1;
int thr = (rand()%100) + 1;
int four = (rand()%100) + 1;
int fiv = (rand()%100) + 1;
cout << "Problem " << wrong + right + 1 << ": Average of" << one << ", " << two << ", " << thr << ", " << four << " and " << fiv << " = ";
cin >> sol;
if(sol == (one+two+thr+four+fiv)/5){
right++;
cout << "Correct!\n";}
else{
wrong++;
cout << "Sorry, the answer was " << one*two << ".\n";}
}
| |