Hello, i just started Coding in C++ i thought the beginer assighments were too easy so i decided to make them more complex.
The job was to create a program that asked three questions
Question 1: What was the date, month, and year Armstrong landed on the moon.
Question 2: Are aliens real?
Question 3: What are the first 30 digits of Pi?
If you got the answer right It would output correct.
But if you got the answer wrong it would output Incorrect.
here is a visual of what i came up with.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int iNeal;
double b;
string c = "Yes";
b = 3.14159265358979323846264338327;
{
cout << "Question 1" << endl;
cout << "Neil Armstrong and his crew landed on what" << endl;
cout << "Date month and year" << endl;
cin >> iNeal, iNeal, iNeal;
if ((iNeal == 7) && (iNeal == 20) && (iNeal == 1969))
cout << "correct" <<endl;
else cout << "Incorrect" << endl;
}
{
cout << "Question 2 " << endl;
cout << "Are aliens real? " << endl;
cout << "Yes or No " << endl ;
cin >> c;
if (( c == "yes" ))
cout << "Emerse yoruself in the beauty of human exploration and find them" << endl;
else cout << "Don't shut yourself to a human realm of reality the universe is more beutiful than anything you could ever imagine" << endl;
}
{
cout << "Question 3 ";
cout << " what are the first 30 values of PI" << endl;
cin >> b;
if ((b == 3.14159265358979323846264338327))
cout << "correct" << endl;
else cout << "Incorrect" << endl;
}
{
cout << "THANKS FOR PLAYING!!! " << endl;
cout << "Practice program made by Juan Wagner " << endl;
cout << "Continuing the legacy... no matter how bad it hurts " << endl;
}
}
The problem is that when i try to answer the fist question the whole program just spits out the result with out any interaction. I know that the problem has to do with the first questions because i remade the program where the first question only requires the year to work and the whole program worked right. Any sudgestions are welcomed.
You have two problems that I see. The first is that iNeal is only one integer, so you can't read multiple values into it. So your if statement checking it will never be true. Second, you have the issue with using cin>>; this leaves a trailing newline in the buffer so subsequent cin>> reads will read that and stop instead of actually reading the next data.
A problem you'll face later on is that no matter what you input for the third question, the program will reject it as incorrect. The reason is a bit complicated. All you need to know is that floating point equality comparisons are very unreliable, and adding more decimals only worsens the problem.