# Happy Pi Day ; a Pi Game!

• March 14th, 2012, 10:21 PM
JRabbit
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;
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

• March 14th, 2012, 11:00 PM
JRabbit
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.

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

• March 14th, 2012, 11:04 PM
SilentNite17
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! :__:
• March 14th, 2012, 11:16 PM
JRabbit
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.
• March 15th, 2012, 07:22 AM
KevinWorkman
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.