Genkora
Frog blast the vent core!
- Reaction score
- 92
alright, I am making a program in java that will allow a user to bet on a number 2-12 and then roll two six sided dice, and then it will display their winnings (which will depend on the odds of rolling the number bet on, 2 and 12 will earn you the most, while 7 gets the least). I have already figured out how to get the probability of rolling any number and I know it works, however I am getting an error on my "else"
here is my code:
If I just leave out the else and everything in it, it returns the correct values (assuming I enter something higher than 7). However, when I try to compile with the else, I get an error saying:
'else' without 'if'
I don't understand what the problem is because the 'if' is clearly there. I also tried just using two 'if's, but I kept getting logical errors with numbers higher than 7 and I couldn't figure out why (in that case it always returned values as if numbers higher than 7 went through the second 'if' anyway).
It is probably something simple I am just not seeing, but I have only been coding for about a week.
here is my code:
Code:
import java.util.Scanner;
import java.util.Random;
public class Dice
{
public static void main (String[] args)
{
Random dice = new Random();
Scanner scan = new Scanner(System.in);
int roll1, roll2, mid = 7, numw, numx, numy, numz;
double val, prob1, prob2, prob3;
prob3 = 36;
System.out.print("Two six sided dice will be rolled, choose a number to bet on between 2 and 12: ");
numx = scan.nextInt();
if (numx > mid);
{
numw = numx;
numy = numw - mid;
numz = numy * 2;
prob1 = (numw - numz) - 1;
prob2 = prob1/prob3;
}
else
{
numw = numx;
prob1 = numw - 1;
prob2 = prob1/prob3;
}
System.out.println("\n"+numw+" "+numy+" "+numz+" "+prob1+" "+prob2);
}
}
If I just leave out the else and everything in it, it returns the correct values (assuming I enter something higher than 7). However, when I try to compile with the else, I get an error saying:
'else' without 'if'
I don't understand what the problem is because the 'if' is clearly there. I also tried just using two 'if's, but I kept getting logical errors with numbers higher than 7 and I couldn't figure out why (in that case it always returned values as if numbers higher than 7 went through the second 'if' anyway).
It is probably something simple I am just not seeing, but I have only been coding for about a week.