Dodian.com Forums

Go Back   Dodian.com Forums > Off Topic > Programming > C Programming > Display Room

Reply
 
Thread Tools Display Modes
Old 11-04-2009, 10:36 PM   #1
Glenash
Noob
Points: 1,063, Level: 7
Points: 1,063, Level: 7 Points: 1,063, Level: 7 Points: 1,063, Level: 7
Activity: 14%
Activity: 14% Activity: 14% Activity: 14%
 
Join Date: Jun 2008
Location: London, England
Posts: 10
Default 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);
    
        }
}
Glenash is offline   Reply With Quote
Old 11-04-2009, 11:36 PM   #2
Zaga
Programmer
Points: 5,522, Level: 17
Points: 5,522, Level: 17 Points: 5,522, Level: 17 Points: 5,522, Level: 17
Activity: 47%
Activity: 47% Activity: 47% Activity: 47%
 
Zaga's Avatar
 
Join Date: Oct 2007
Location: ██████████████
Posts: 1,021
Default

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.
__________________
Zaga is offline   Reply With Quote
Old 11-04-2009, 11:45 PM   #3
Scyth
Jesse
Points: 9,212, Level: 22
Points: 9,212, Level: 22 Points: 9,212, Level: 22 Points: 9,212, Level: 22
Activity: 60%
Activity: 60% Activity: 60% Activity: 60%
 
Scyth's Avatar
 
Join Date: Apr 2008
Location: ◄███▓░X░▓███►
Posts: 2,742
Send a message via MSN to Scyth
Default

you had to pick the one code, I really suck at didn't ya?
__________________

Quote:
Originally Posted by Zaven View Post
Meh.. wasn't thinking.
Scyth is offline   Reply With Quote
Old 11-04-2009, 11:50 PM   #4
Glenash
Noob
Points: 1,063, Level: 7
Points: 1,063, Level: 7 Points: 1,063, Level: 7 Points: 1,063, Level: 7
Activity: 14%
Activity: 14% Activity: 14% Activity: 14%
 
Join Date: Jun 2008
Location: London, England
Posts: 10
Default

Quote:
Originally Posted by Zaga View Post
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
Glenash is offline   Reply With Quote
Old 11-04-2009, 11:53 PM   #5
Zaga
Programmer
Points: 5,522, Level: 17
Points: 5,522, Level: 17 Points: 5,522, Level: 17 Points: 5,522, Level: 17
Activity: 47%
Activity: 47% Activity: 47% Activity: 47%
 
Zaga's Avatar
 
Join Date: Oct 2007
Location: ██████████████
Posts: 1,021
Default

Quote:
Originally Posted by Glenash View Post
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)
__________________
Zaga is offline   Reply With Quote
Old 11-04-2009, 11:59 PM   #6
Glenash
Noob
Points: 1,063, Level: 7
Points: 1,063, Level: 7 Points: 1,063, Level: 7 Points: 1,063, Level: 7
Activity: 14%
Activity: 14% Activity: 14% Activity: 14%
 
Join Date: Jun 2008
Location: London, England
Posts: 10
Default

Yeh you should, i'm so glad i learned it.
Glenash is offline   Reply With Quote
Old 11-15-2009, 11:52 PM   #7
Pheoby1
Noob
 
Join Date: Oct 2009
Posts: 17
Default re- competiton

All that stuff is soo complicated..
Pheoby1 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 12:28 PM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Dodian