bool quiz

How can I expand this to three differnt questions? Right now, it is only one generic question repeated three time..
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

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#include <cstdlib> 
#include <cctype>

class toLower {public: char operator()(char c) const {return tolower(c);}};


  bool askQuestion (string useranswer)
{
  bool result = false;

  string youranswer; 

  cout << "What is a computer error called?: " << endl; 
  cin >> youranswer;
  cin.ignore (1000, 10);
  
transform(youranswer.begin(), youranswer.end(), youranswer.begin(), toLower());

   
  if (youranswer == useranswer)
  {
  cout << " Correct!" << endl;
  result = true;
  } 
  else 
  cout << "wrong " << endl;
  return result;

}


int main()
	
{  
     
  int correct = 0; 
  if (askQuestion( "bug")) correct++; 
  if (askQuestion( "bug")) correct++; 
  if (askQuestion( "bug")) correct++; 
  cout << "#of correct answers: " << correct << " Out of 3 " << endl;


	return 0;
}

  
How about you change
bool askQuestion (string useranswer)
to
bool askQuestion (string userquestion, string useranswer)

and
cout << "What is a computer error called?: " << endl;
to
cout << userquestion << endl;

Another improvement would be to call askQuestion() in a loop which reads the questions and answers form an array or a file so that you can more flexibly add and remove questions.
I thought about the first part but thanks for clarifying the rest. I will see if I can use it without a loop first, then i will try a loop.
Topic archived. No new replies allowed.