Problem with simple multiple choice quiz

I'm working on a simple multiple choice quiz for my end of semester project. Here's what I've got so far

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
#include <cstdlib>
#include <iostream>
#include <string>
#include <windows.h>


using namespace std;


int main()
{
	string playerName;
	char digit = 0;
    int digit2 = 0;
	char answer;
	 
	



	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
	cout << "Welcome to the C++ Quiz!\n\n";                                          // get user input and start the game
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
	cout << "Please enter your name ";
	getline(cin, playerName); 
	cout << playerName << " are you ready to test your knowledge of C++?\n\n\t";
	cout << "If so, press enter to continue\n\t"; 
	digit = cin.get();
	
	 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 3);                    // change question colour

	cout << "Question 1 - Who Developed C++?\n\n\t";                                 // question 1

	 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);

	cout << "A) Alexander Stepanov\n\t";
	cout << "B) Bjarne Stroustrup\n\t"; 
	cout << "C) Herb Sutter\n\n\t"; 

	cout << "What is your answer, a, b or c?\t ";
	cin << answer; 

	    if (answer = "b")
	        {		    
			  cout << "Correct!"; 
	        }


		
		    
	    
	    cin.get();
		getchar();
	    return 0; 
}


Everytime I run it from here it gives me loads of errors, the most common being "could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'"

could anyone help me find a solution?

Also I would like to make the right answer flash green when the player gets it correct. How would I go about doing this?

Thanks in advance.

Well, this line is incorrect:
1
2
3
4
 if (answer = "b")    //assigning the string value of "b" to answer, which is a char
	        {		    
			  cout << "Correct!"; 
	        }


when you compare two values with the intent to check for equality, you need to use the == operator, and not the assignment operator =. You are also assigning a string value to a char. the correct syntax is

1
2
if(answer == 'b')
...


To flash the answer green, you can either clear the screen and then output the string with the correct formatting applied a bunch of times, or get a buffer and write to a location.

i recommend the first way.

edit:

how devious was that?
 
cin << answer; 


should be:
 
cin >> answer;


lol

;)
Last edited on
Damn me and my typos! :P

cheers! :)
Topic archived. No new replies allowed.