Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Happy Pi Day ; a Pi Game!

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Location
    Crete, Illinois
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Happy Pi Day ; a Pi Game!

    Hello guys! My first post here at JavaProgrammingForums, so thank you for having me!

    I'm making a game to see how many digits of Pi you can get correct in a row; I'm sure it's been made before but I like doing stuff like this.

    I ran this code and typed in "1" expecting for it to recognize that my input equaled the first digit to the right of pi.
    The console looked like this;
    "
    Run:
    1 //my input
    10 //consoles output
    Build Successful
    "
    Tried it a few more times, and it seems whatever I input the console multiplies it by 10 and spits out that answer. :S

    Here is my code;
    /*
     * Created By Josh Beckwith 
     * on March 14, 2012.       
     */
    package pigame;
     
    import java.util.Scanner;
     
    public class PiGame 
    {
        static int iPi01 = 1415926535;
        static int iPi02 = 897932384;
        static int iPi03 = 626433832;
        static int iPi04 = 795028841;
        static int iPi05 = 971693993;
        static int iPi06 = 751058209;
        static int iPi07 = 74944592;
        static int iPi08 = 30;
        static int iPi09 = 781640628;
        static int iPi10 = 620899862;
        static int iPi11 = 803482534;
        static int iPi12 = 211706798;
        static int iNumber;
        static int iDumber;
        static int iScore = 0;
        static boolean bCorrect = true;
     
        public static void main(String[] args) 
        {
            for(int i = 1;bCorrect == true;i++)
            {
                //grab input and store as 'input'
                Scanner input = new Scanner(System.in);
                int iInt;
     
                iInt = input.nextInt();
                System.out.print(iInt);
                    if(i < 10) {
                        iNumber = 10-i;
                        iDumber = iPi01/10^iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 19){
                        iNumber = 9-i;
                        iDumber = iPi02/10^iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 28){
                        iNumber = 9-i;
                        iDumber = iPi03/10^iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 37){
                        iNumber = 9-i;
                        iDumber = iPi04/10^iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 46){
                        iNumber = 9-i;
                        iDumber = iPi05/10^iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 55){
                        iNumber = 9-i;
                        iDumber = iPi06/10^iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 63){
                        iNumber = 8-i;
                        iDumber = iPi07/10^iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 65){
                        iNumber = 2-i;
                        iDumber = iPi08/10^iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 74){
                        iNumber = 9-i;
                        iDumber = iPi09/10^iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 83){
                        iNumber = 9-i;
                        iDumber = iPi10/10^iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 92){
                        iNumber = 9-i;
                        iDumber = iPi11/10^iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 101){
                        iNumber = 9-i;
                        iDumber = iPi12/10^iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    }
            } //ends for loop
        System.out.println(iScore);
        } //ends method
    } //ends class


  2. #2
    Junior Member
    Join Date
    Mar 2012
    Location
    Crete, Illinois
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Happy Pi Day ; a Pi Game!

    Update;

    My code is semi functional now.

    I guess 1; and it moves onto the second digit and I guess 4 and the game ends. The game ends after the second guess no matter the number I chose, I tried 0-9.

    /*
     * Created By Josh Beckwith 
     * on March 14, 2012.       
     */
    package pigame;
     
    import java.util.Scanner;
     
    public class PiGame 
    {
        static int iPi01 = 1415926535;
        static int iPi02 = 897932384;
        static int iPi03 = 626433832;
        static int iPi04 = 795028841;
        static int iPi05 = 971693993;
        static int iPi06 = 751058209;
        static int iPi07 = 74944592;
        static int iPi08 = 30;
        static int iPi09 = 781640628;
        static int iPi10 = 620899862;
        static int iPi11 = 803482534;
        static int iPi12 = 211706798;
        static int iNumber;
        static int iDumber;
        static int iScore = 0;
        static boolean bCorrect = true;
     
        public static void main(String[] args) 
        {
            for(int i = 1;bCorrect == true;i++)
            {
                //grab input and store as 'input'
                Scanner input = new Scanner(System.in);
                int iInt;
     
                iInt = input.nextInt();
                System.out.print(iInt);
                    if(i < 10) {
                        iNumber = 10-i;
                        iNumber = (int)Math.pow(10, iNumber);
                        iDumber = iPi01 / iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 19){
                        iNumber = 9-i;
                        iNumber = (int)Math.pow(10, iNumber);
                        iDumber = iPi02 / iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 28){
                        iNumber = 9-i;
                        iNumber = (int)Math.pow(10, iNumber);
                        iDumber = iPi03 / iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 37){
                        iNumber = 9-i;
                        iNumber = (int)Math.pow(10, iNumber);
                        iDumber = iPi04 / iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 46){
                        iNumber = 9-i;
                        iNumber = (int)Math.pow(10, iNumber);
                        iDumber = iPi05 / iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 55){
                        iNumber = 9-i;
                        iNumber = (int)Math.pow(10, iNumber);
                        iDumber = iPi06 / iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 63){
                        iNumber = 8-i;
                        iNumber = (int)Math.pow(10, iNumber);
                        iDumber = iPi07 / iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 65){
                        iNumber = 2-i;
                        iNumber = (int)Math.pow(10, iNumber);
                        iDumber = iPi08 / iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 74){
                        iNumber = 9-i;
                        iNumber = (int)Math.pow(10, iNumber);
                        iDumber = iPi09 / iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 83){
                        iNumber = 9-i;
                        iNumber = (int)Math.pow(10, iNumber);
                        iDumber = iPi10 / iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 92){
                        iNumber = 9-i;
                        iNumber = (int)Math.pow(10, iNumber);
                        iDumber = iPi11 / iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    } else if (i < 101){
                        iNumber = 9-i;
                        iNumber = (int)Math.pow(10, iNumber);
                        iDumber = iPi12 / iNumber;
                            if (iDumber != iInt)
                            {
                                bCorrect = false;
                            }
                            else if (iDumber == iInt)
                            {
                                iScore = iScore + 1;
                            }
                    }
            } //ends for loop
        System.out.println(iScore);
        } //ends method
    } //ends class

  3. #3
    Member
    Join Date
    Feb 2012
    Location
    West USA
    Posts
    67
    My Mood
    Inspired
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Happy Pi Day ; a Pi Game!

    Haha wow looks like a fun game! Wish I could help...

    How many digits of Pi have you memorized? I have 121! :__:

  4. #4
    Junior Member
    Join Date
    Mar 2012
    Location
    Crete, Illinois
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Happy Pi Day ; a Pi Game!

    I have about 30ish atm :-) I was actually hoping to get around 100+ by creating and playing this game.

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Happy Pi Day ; a Pi Game!

    If you want help, you'll have to provide an SSCCE that demonstrates the problem. That seems like way too much code for simply inputting a single number at a time and checking it against a known value.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. HAPPY HOLIDAYS TO FELLOW MATES :D
    By chronoz13 in forum Totally Off Topic
    Replies: 4
    Last Post: January 9th, 2012, 05:15 AM
  2. Hi all.. happy to joint you all
    By suganthant in forum Member Introductions
    Replies: 2
    Last Post: November 16th, 2011, 10:33 AM
  3. Off Topic: Happy Songs?
    By KevinWorkman in forum The Cafe
    Replies: 5
    Last Post: March 3rd, 2011, 09:46 PM
  4. HAPPY 2nd BIRTHDAY JAVA PROGRAMMING FORUMS!!!
    By JavaPF in forum The Cafe
    Replies: 55
    Last Post: May 24th, 2010, 03:43 AM