PDA

View Full Version : C++ Challenge.


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);

}
}

Zaga
11-04-2009, 11:36 PM
You could just divide the number by 2 and if it doesn't come out to be a whole number than say it's odd, otherwise say it's even.

That would be a lot simpler, plus it would support more than 10 numbers.

Scyth
11-04-2009, 11:45 PM
you had to pick the one code, I really suck at didn't ya?

Glenash
11-04-2009, 11:50 PM
You could just divide the number by 2 and if it doesn't come out to be a whole number than say it's odd, otherwise say it's even.

That would be a lot simpler, plus it would support more than 10 numbers.

It's a challenge i'm not asking for help. lool

Zaga
11-04-2009, 11:53 PM
It's a challenge i'm not asking for help. lool

Ik, I'm just saying.


Plus I never bothered to learn C++ even though I should. (I'll probably learn it next year)

Glenash
11-04-2009, 11:59 PM
Yeh you should, i'm so glad i learned it.

Pheoby1
11-15-2009, 11:52 PM
All that stuff is soo complicated.. :(