# Thread: Compilation Problem

1. Member
Join Date
Sep 2008
Posts
29
Rep Power
0

## Compilation Problem

I dont get it, like the compiler isn't adding right...

Java Code:
```package JavaHowToProgram;

import java.util.Random;

public class RandomIntegers
{
public static void main( String args[] )
{

Random randomNumbers = new Random();
int face;
int face2;
int face3;
int face4;
int sum;
int sum2;

for ( int counter = 1; counter <= 1; counter++ )
{
face = 1 + randomNumbers.nextInt( 100 );

System.out.printf( "%d\n", face );

face2 = 1 + randomNumbers.nextInt( 100 );

System.out.printf( "%d\n", face );

face3 = 1 + randomNumbers.nextInt( 100 );

System.out.printf( "%d\n", face2 );

face4 = 1 + randomNumbers.nextInt( 100 );

System.out.printf( "%d\n", face );

sum = face + face2;
sum2 = face3 + face4;

System.out.printf( "The sum for Player One is %d\n", sum );
System.out.printf( "The sum for Player Two is %d\n", sum2 );

if ( sum > sum2 )
System.out.println( "Player One has won the game!/n" );
if ( sum2 > sum )
System.out.println( "Player Two has won the game!\n" );
if ( sum == sum2 )
System.out.println( "Tie!" );
if ( counter % 5 == 0 )
System.out.println();
}
}
}```
Compiler\/
{
72
72
2
72
The sum for Player One is 74
The sum for Player Two is 107
Player Two has won the game!
}Compiler/\
Last edited by whosadork; 09-09-2008 at 02:31 AM. Reason: Compiler at bottom...

2. ## system dot out not matched

your diagnostics do not match up with your variables,,.....

3. I dont get it, like the compiler isn't adding right...
I haven't looked at your code yet, but if I were asked to bet if this were a compiler error or a bug in your program, I'll put my money on this being your bug.

Edit: oh yeah. Please read through your code carefully, especially the "face" variables.
Last edited by Fubarable; 09-09-2008 at 02:37 AM.

4. Member
Join Date
Sep 2008
Posts
29
Rep Power
0
no i got it, yeah the variables arn't matched up right, thx...
i cant beleive i didn't find that....

5. Member
Join Date
Sep 2008
Posts
29
Rep Power
0
the code in bold are the variables i missed...

Java Code:
```package JavaHowToProgram;

import java.util.Random;

public class RandomIntegers
{
public static void main( String args[] )
{

Random randomNumbers = new Random();
int face;
int face2;
int face3;
int face4;
int sum;
int sum2;

for ( int counter = 1; counter <= 1; counter++ )
{
face = 1 + randomNumbers.nextInt( 100 );

System.out.printf( "%d\n", [B]face[/B] );

face2 = 1 + randomNumbers.nextInt( 100 );

System.out.printf( "%d\n", [B]face2[/B] );

face3 = 1 + randomNumbers.nextInt( 100 );

System.out.printf( "%d\n", [B]face3[/B] );

face4 = 1 + randomNumbers.nextInt( 100 );

System.out.printf( "%d\n", [B]face4[/B] );

sum = face + face2;
sum2 = face3 + face4;

System.out.printf( "The sum for Player One is %d\n", sum );
System.out.printf( "The sum for Player Two is %d\n", sum2 );

if ( sum > sum2 )
System.out.println( "Player One has won the game!\n" );
if ( sum2 > sum )
System.out.println( "Player Two has won the game!\n" );
if ( sum == sum2 )
System.out.println( "Tie!" );
if ( counter % 5 == 0 )
System.out.println();
}
}
}```

6. Member
Join Date
Sep 2008
Posts
29
Rep Power
0

## Suggestions

Could i use some suggestions for the game, i know it sucks now but it might get better.

Java Code:
```package JavaHowToProgram;

import java.util.Random;
import java.util.Scanner;

public class RandomIntegers
{
public static void main( String args[] )
{

Random randomNumbers = new Random();
int face;
int face2;
int face3;
int face4;
int sum;
int sum2;
int NumberRoll;
String Name;
String Name2;

for ( int counter = 1; counter <= 1; counter++ )
{

System.out.printf( "Welcome to a game of really big dice!\nHave Fun!\n\n" );

Scanner input = new Scanner( System.in );

System.out.printf( "Enter Your name:\n" );
Name = input.next();

System.out.printf( "Enter your opponents name:\n" );
Name2 = input.next();

System.out.printf( "Enter how high you want to rolls to go:\n" );
NumberRoll = input.nextInt();

System.out.printf( "\n%s's Rolls\n", Name );

face = 1 + randomNumbers.nextInt( NumberRoll );

System.out.printf( "%d\n", face );

face2 = 1 + randomNumbers.nextInt( NumberRoll );

System.out.printf( "%d\n", face2 );

System.out.printf( "%s's Rolls\n", Name2 );

face3 = 1 + randomNumbers.nextInt( NumberRoll );

System.out.printf( "%d\n", face3 );

face4 = 1 + randomNumbers.nextInt( NumberRoll );

System.out.printf( "%d\n\n", face4 );

sum = face + face2;
sum2 = face3 + face4;

System.out.printf( "The sum for %s is %d\n", Name, sum );
System.out.printf( "The sum for %s is %d\n", Name2, sum2 );

if ( sum > sum2 )
System.out.printf( "%s has won the game!\n", Name );
if ( sum2 > sum )
System.out.printf( "%s has won the game!\n", Name2 );
if ( sum == sum2 )
System.out.println( "Tie!" );
if ( face == face2 )
System.out.printf( "%s has rolled the same two numbers, %d, and %d,\n The chances of doing that are %d to 1!\n", Name, face, face2, NumberRoll);
if ( face3 == face4 )
System.out.printf( "%s has rolled the same two numbers, %d, and %d,\n The chances of doing that are %d to 1!\n\n", Name2, face3, face4, NumberRoll );
if ( NumberRoll == 1 )
System.out.printf( "" );
if ( counter % 5 == 0 )
System.out.println();
}
}
}```
\/Compiler
{
Welcome to a game of really big dice!
Have Fun!

Enter Your name:
Jerry
Enter your opponents name:
CPU
Enter how high you want to rolls to go:
500

Jerry's Rolls
240
391
CPU's Rolls
18
438

The sum for Jerry is 631
The sum for CPU is 456
Jerry has won the game!

}/\Compiler

7. Some of your if conditions are mutually exclusive and could be coded as if else if else vs if if if

And you could add some comments to explain why you are doing something.
if ( counter % 5 == 0 ) // leave blank every 5 lines
System.out.println();

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•