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
|
#include <iostream>
#include <string>
//#include <cstdio> // printf, scanf, puts, NULL
//don't want this
#include <cstdlib> // srand, rand
#include <ctime> // time
using namespace std;
#define TESTING
struct WordDef
{
string word;
string def;
};
int main() {
srand (time(NULL));
const WordDef rootList[] = {
{"acr/o" , "extreme stuff"},
{"cardi/o", "heart stuff"},
{"cyan/o" , "dark blue stuff"},
{"cyt/o" , "cell stuff"},
{"dermat/o", "skin stuff"},
{"duoden/o", "duodenum stuff"},
{"electro", "a style of dance music with a fast"
" beat and synthesized backing track"}};
const int count = sizeof(rootList)/sizeof(rootList[0]);
// size of whole list / size of first element
#ifdef TESTING
// just for testing, display list
for(int i = 0; i < count; ++i)
{
cout << "[" << rootList[i].word << "]\n"
<< rootList[i].def << "\n";
}
cout << "\n";
#endif
for(int i = 0; i < 5; ++i)
{
int j = rand() % count; // do not add 1
// (valid indices are 0 - N-1 for an array of size N)
cout << rootList[j].word << " means?\n";
string def;
getline(cin, def); // use getline() function as cin >> can't deal with spaces!
if(def == rootList[j].def)
cout << "correct!\n";
else
cout << "wrong!\n";
cout << "\n";
}
return 0;
}
|