#include <iostream>
#include <iomanip>
#include <windows.h>
#include <conio.h>
#include <cmath>
usingnamespace std;
main()
{
string ans2,ans3,ans4,ans5;
int score=0;
{
//1
system("cls");
cout<<"1.This is the Modern Age.";
Sleep(3000);
system("cls");
cout<<"What is your answer?\nAnswer:";
cin>>ans2;
if (( ans2 == "this is the modern age." )||( ans2 == "THIS IS THE MODERN AGE."))
{
cout<<"YOU ARE CORRECT!\n\n\n\n\nCurrent Score:";
score = score+20;
Sleep(2000);
}
else
{
system("cls");
score= 0;
cout<<"YOU ARE INCORRECT!\nSubtracting 15 Points from your Score\n\n\n\n\nCurrent Score:["<<score<<"].";
Sleep(3000);
}
}
system("PAUSE>>NULL");
return 0;
}
Try replacing line 26 with this: getline(cin, ans2);
Reference wrote:
Notice that the istream extraction operations use whitespaces as separators; Therefore, this operation will only extract what can be considered a word from the stream. To extract entire lines of text, see the string overload of global function getline.
{
//1
Hard1:
system("cls");
cout<<"1.This is the Modern Age.";
Sleep(3000);
system("cls");
cout<<"What is your answer?\nAnswer:";
getline(cin, ans2);
{
if ( ans2 == "This is the modern age.")
{
system("cls"); score = +20;
cout<<"YOU ARE CORRECT!\n\n\n\n\nCurrent Score:["<<score<<"].";
Sleep(2000);
goto Hard2;
}
else
{
system("cls"); score= 0;
cout<<"YOU ARE INCORRECT!\nSubtracting 15 Points from your Score\n\n\n\n\nCurrent Score:["<<score<<"";
Sleep(3000);
}
}
}
}
{
//2
Hard2:
system("cls");
cout<<"1.The measure of intelligence is the ability to change.";
Sleep(3000);
system("cls");
cout<<"What is your answer?\nAnswer:";
getline(cin, ans3);
if ( ans3 == "The measure of intelligence is the ability to change.")
{
system("cls"); score = +20;
cout<<"YOU ARE CORRECT!\n\n\n\n\nCurrent Score:["<<score<<"].";
Sleep(2000);
goto Hard3;
}
else
{
system("cls"); score = 0;
cout<<"YOU ARE INCORRECT!\nSubtracting 2 Points from your Score\n\n\n\n\nCurrent Score:["<<score<<"].";
Sleep(3000);
}
}
{
//3
Hard3:
system("cls");
cout<<"1. Quotation is a serviceable substitute for wit.\n\n\n\n\nCurrent Score:["<<score<<"].";
Sleep(3000);
system("cls");
cout<<"What is your answer?\nAnswer:";
cin>>ans4;
if ( ans4 == "Quotation is a serviceable substitute for wit.")
{
system("cls"); score = +20;
cout<<"YOU ARE CORRECT!\n\n\n\n\nCurrent Score:["<<score<<"].";
Sleep(2000);
goto Hard1;
}
else
{
system("cls"); score = -15;
cout<<"YOU ARE INCORRECT!\nSubtracting 2 Points from your Score\n\n\n\n\nCurrent Score:["<<score<<"].";
Sleep(3000);
}
}
my problem now is that it won't allow me to answer anything. it skips directly to incorrect
Ah, good old "mix stream extraction operator and getline and break everything" error.
You see, when you write something and console and press enter, >> operator will read up untill endline symbor and stop before that, leaving it in input buffer.
Then when you invoke getline, it will encounter it immideatly and think that line has ended, so it will actually read empty string.