Glenash
11-04-2009, 10:36 PM
Here is the challenge:
Why does the code that I provide whenever a entry is entered only recognizes everything as even?
*HINT*
It fully complies so it's not a syntax error.
*END HINT*
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int main()
{
cout << "Hello World!\n";
string CHOICE;
cout << "If you wish to exit do so by typing \"exit\" now otherwise type \"no\"\n";
cin >> CHOICE;
if(CHOICE == "exit")
{
cout << "Exiting...";
Sleep(1000);
return 0;
}
else
{
Beginning:
cout << "Pick 1-10\n" << "If you wish to exit from here type in 0 (zero)\n";
int choice = NULL; //Resets choice to nothing
cin >> choice;
if(choice == 2, 4, 6, 8, 10) //Sees if it's even
{
cout << "It is even\n";
Sleep(1000);
goto Beginning;
}
else if(choice == 1, 3, 5, 7, 9) //Sees if it's odd
{
cout << "It is odd\n";
Sleep(1000);
goto Beginning;
}
else if(choice == 0) //Sees if it's zero the exit command
{
cout << "Exiting...\n";
Sleep(400);
return 0;
}
else //Sees is it's invalid
{
cout << "Invalid entry.\n";
Sleep(400);
goto Beginning;
}
Sleep(1000);
}
}
Why does the code that I provide whenever a entry is entered only recognizes everything as even?
*HINT*
It fully complies so it's not a syntax error.
*END HINT*
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int main()
{
cout << "Hello World!\n";
string CHOICE;
cout << "If you wish to exit do so by typing \"exit\" now otherwise type \"no\"\n";
cin >> CHOICE;
if(CHOICE == "exit")
{
cout << "Exiting...";
Sleep(1000);
return 0;
}
else
{
Beginning:
cout << "Pick 1-10\n" << "If you wish to exit from here type in 0 (zero)\n";
int choice = NULL; //Resets choice to nothing
cin >> choice;
if(choice == 2, 4, 6, 8, 10) //Sees if it's even
{
cout << "It is even\n";
Sleep(1000);
goto Beginning;
}
else if(choice == 1, 3, 5, 7, 9) //Sees if it's odd
{
cout << "It is odd\n";
Sleep(1000);
goto Beginning;
}
else if(choice == 0) //Sees if it's zero the exit command
{
cout << "Exiting...\n";
Sleep(400);
return 0;
}
else //Sees is it's invalid
{
cout << "Invalid entry.\n";
Sleep(400);
goto Beginning;
}
Sleep(1000);
}
}