I am stuck on this particular part of the program called while (user == gullible). Here is the code I have written out so far. Nothing too complicated.
// Gullible Patric Bernard
#include <iostream>
using std::cin; /* Using std::cin,cout, and endl are just so I don't have to include all of using namespace std;*/
using std::cout;
using std::endl;
int main()
{
int x = 5; // x is the variable that the user has to enter to end the program.
int y,z; // y is the variable that the user enters, z is used for a counter in my for loop.
cout << "Please enter a number that isn't " << x <<"!" << endl;
cin >> y;
for(z = 0; z <= 9; z++) //for loop repeats 10 times.
{
x = x + y;
if(z > 8) //if the for loop repeats 10 times, the program will run this iteration, terminating the program.
{
cout << "Wow, you have a lot more patience than I do. You win!" << endl;
cin >> y; // only used for a holding point in the program so the user can see the end result. Entering a varialbe will end the program.
}
elseif (x == y) //if the user enters the number they are asked not too, this else if loop will scold them, and then break out of the for loop, ending the program.
{
cout << "You entered the number " << y << "!" << endl;
cout <<"Hey! You weren't supposed to enter the number " << x << "!"<< endl;
cin >> y;
break;
}
elseif (x != y) // if the user does not enter the value they are told not too, they will keep being asked to enter in a value.
{
cout << "You entered the number " << y << "!" << endl;
cout << "Please enter a number that isn't " << x <<"!" << endl;
cin >> y;
}
}
The issue I am having is with getting the numbers to add up on the final challenge of this program. If I enter in x = x + y; right after I open my for loop, I can get the values to start adding up, and saying please do not enter the value of x, which is the sum of x and y (y being the users entered value) but when I enter in the value they are not supposed to enter, It does not terminate the program.
// Gullible Patric Bernard
#include <iostream>
using std::cin; /* Using std::cin,cout, and endl are just so I don't have to include all of using namespace std;*/
using std::cout;
using std::endl;
int main()
{
int x = 5; // x is the variable that the user has to enter to end the program.
int y,z; // y is the variable that the user enters, z is used for a counter in my for loop.
cout << "Please enter a number that isn't " << x <<"!" << endl;
cin >> y;
for(z = 0; z <= 9; z++) //for loop repeats 10 times.
{
x = x + y;
if(z > 8) //if the for loop repeats 10 times, the program will run this iteration, terminating the program.
{
cout << "Wow, you have a lot more patience than I do. You win!" << endl;
cin >> y; // only used for a holding point in the program so the user can see the end result. Entering a varialbe will end the program.
}
elseif (x == 2*y) //if the user enters the number they are asked not too, this else if loop will scold them, and then break out of the for loop, ending the program.
{
cout << "You entered the number " << y << "!" << endl;
cout <<"Hey! You weren't supposed to enter the number " << x-y << "!"<< endl;
cin >> y;
break;
}
elseif (x != 2*y) // if the user does not enter the value they are told not too, they will keep being asked to enter in a value.
{
cout << "You entered the number " << y << "!" << endl;
cout << "Please enter a number that isn't " << x <<"!" << endl;
cin >> y;
}
}
return 0;
}