 |
11-04-2009, 10:36 PM
|
#1
|
|
Noob
Join Date: Jun 2008
Location: London, England
Posts: 10
|
C++ Challenge.
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*
Code:
#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);
}
}
|
|
|
11-04-2009, 11:36 PM
|
#2
|
|
Programmer
Join Date: Oct 2007
Location: ██████████████
Posts: 1,021
|
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.
__________________
|
|
|
11-04-2009, 11:45 PM
|
#3
|
Join Date: Apr 2008
Location: ◄███▓░X░▓███►
Posts: 2,742
|
you had to pick the one code, I really suck at didn't ya?
__________________
Quote:
Originally Posted by Zaven
Meh.. wasn't thinking.
|
|
|
|
11-04-2009, 11:50 PM
|
#4
|
|
Noob
Join Date: Jun 2008
Location: London, England
Posts: 10
|
Quote:
Originally Posted by Zaga
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
|
|
|
11-04-2009, 11:53 PM
|
#5
|
|
Programmer
Join Date: Oct 2007
Location: ██████████████
Posts: 1,021
|
Quote:
Originally Posted by Glenash
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)
__________________
|
|
|
11-04-2009, 11:59 PM
|
#6
|
|
Noob
Join Date: Jun 2008
Location: London, England
Posts: 10
|
Yeh you should, i'm so glad i learned it.
|
|
|
11-15-2009, 11:52 PM
|
#7
|
|
Noob
Join Date: Oct 2009
Posts: 17
|
re- competiton
All that stuff is soo complicated..
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 05:53 AM.
|
 |
|