Hi. I'm trying to make a simple question program, my first question doesn't work (if you enter the wrong answer/an answer that isn't an integer, you get stuck in an infinite loop).
However, my second question works fine even though the code is quite similar.
Sorry if I'm being a bit vague, here is the code so you can try it for yourself.
Any help is appreciated. :(
Also any suggestions on how I could improve my code? I am new. ^^
#include <iostream>
#include <string>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
using namespace std;
int main()
{
int integervalue;
string chtest;
char X;
/*First Question*/
do
{
cout<<"Please type a number then press Enter: \n\n\n";
cin>> integervalue;
if(integervalue>-9999999999999)
{
cout<<"\n\n\nYay!\n\n\n";
}
else
{
cout<<"\n\n\nTry again.\n\n\n";
}
} while (integervalue == X);
cin.get();
cout<<"Press Enter to go to the next question.";
cin.get();
/*Clear the CMD*/
system("cls");
/*Second Question*/
do
{
cout<<"Please type the word 'Cplusplus' then press Enter: \n\n\n";
cin>> chtest;
if(chtest=="Cplusplus")
{
cout<<"\n\n\nYay!\n\n\n";
}
else
{
cout<<"\n\n\nTry again.\n\n\n";
}
} while (chtest != "Cplusplus");
cout<<"Press Enter to exit.";
}