I'am trying to build a simple quiz program in C++ but I'am getting a runtime error, the source code of my quiz program is given below.
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
string name;
char answer[100];
int age,n=0;
cout<<"Enter your name:- ";
getline(cin,name);
cout<<"Welcome to this quiz game "<<name<<endl;
cout<<"Enter your age :-";
cin>>age;
if(age<=10)
{
//Beginning of Question no.1
cout<<"Who was the first president of India :- ";
cin.ignore();
cin.getline(answer,100); //User Inputs the answer here
{
if(answer=="Rajendra Prasad" || answer=="rajendra Prasad" || answer=="rajendra prasad")
{
cout<<answer;
cout<<"Your answer is right.";
n=n+10;
cout<<"You won "<<n<<" points :)";
}
else
cout<<"Your answer is wrong.\nYou won 0 points but better luck next time.";
//End of Question no.1
}
}
}
But whenever user inputs the answer even though if the answer is right the execution directly jumps to else-statement instead of executing if-statement, so if anybody can help me solve this problem then I will be very thankful to you.
Aucun commentaire:
Enregistrer un commentaire