See program below. I keep getting a Lexical preprocessor error \'iostream\' not
ID: 3793883 • Letter: S
Question
See program below. I keep getting a Lexical preprocessor error 'iostream' not found. I am not sure what I am doing wrong.
#include <iostream>
using namespace std;
int main()
{
int toothpicks, h_pick, c_pick;
bool game_finished;
do {
game_finished = false;
toothpicks = 23;
while (!game_finished)
{
cout << "Welcome to the toothpick game!" <<endl;
cout << "Please pick up your toothpick(s). Choose between 1, 2, and 3." << endl;
cin >> h_pick;
toothpicks = toothpicks - h_pick;
cout << toothpicks << " toothpicks are remaining." << endl;
if (toothpicks == 1 && c_pick == 1)
{
cout << "You have won! Congratulations!" << endl;
game_finished = true;
}
if (toothpicks >4)
{
c_pick = 4 -h_pick;
cout << "The computer took " << c_pick << " toothpick(s)." << endl;
}
else if (toothpicks >= 2 && toothpicks <= 4)
c_pick = toothpicks - 1;
cout << "The computer took " << c_pick << " toothpick(s)." << endl;
}
c_pick = 1;
if (toothpicks == 1|| h_pick == 1)
cout << "The computer has won! Too bad!" << endl;
game_finished = true;
if (h_pick > 3 || h_pick < 1)
{
cout << "Please enter a correct value." << endl;
continue;
}
if (toothpicks < 0)
{
cout << "Game will now restart. (Press 4 to quit)" << endl;
cin >> h_pick;
break;
}
}
while (toothpicks > 0);
return 0;
}
Explanation / Answer
The program is fine. This kind of issue occurs due to several reasons:
Try to rewrite the program in an online compiler and try.