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