as i finished the project I kept trying to close the brackets but it kept saying "while expecting" and " reached end of file while parsing"
I've re read the code and the book 6 times and i can't find the mistake. Any help would be really appreciated.
Heres the code. The program is a maths flash card game. it randomly generates a simple sum and it gives you a set amount of time to figure out the answer
//first, allow for input getting
import javax.swing.*;
//create a class named S1P4
public class S1P4
{
private static int sign;
//main method (throws Exception) added for Thread.sleep()
public static void main (String[] args) throws Exception
{
//this will be how many 1/2 seconds the user gets
int difficulty;
difficulty = Integer.parseInt(JOptionPane.showInputDialog("How good are you?\n"+
"1 = Genius..\n"+"10 = Retart"));
//this will tell the loop whether to continue or not:
boolean cont = false;
//the contents of the main method are about to be enclosed in a
// do while loop...
do
{
//reset cont to false
cont = false;
//random numbers for the equation
double num1 = (int)(Math.round(Math.random()*10));
//this do..while loop prevents exceptions. num2 mustbe
//declared outside of the do while so the "while" part can
//see it. It will still be initialized inside the do part,
//thought
double num2;
{
//init num2
num2 = (int)(Math.round(Math.random()*3));
//will store answer
double answer;
//make stuff noticable
System.out.println("\n\n*****");
if(sign==0)
{
//tell user and calculate answer
System.out.println(num1+"times"+num2);
answer = num1*num2;
}
else if(sign==1)
{
//tell user and calculate answer
System.out.println(num1+"divided by"+num2);
answer = num1/num2;
}
else if(sign==1)
{
//tell user answer and calculate
System.out.println(num1+"plus"+num2);
answer = num1+num2;
}
else if(sign==1)
{
//tell user answer and calculate
System.out.println(num1+"minus"+num2);
answer = num1-num2;
}
else
{
//tell user and calculate answer
System.out.println(num1+"%"+num2);
answer = num1%num2;
}
//make it easier to read...
System.out.println("*****\n");
//count down from difficulty... use for a loop!
for(int i = difficulty;i>=0;i--)
{
//count down at double speed!
System.out.println(i+"...");
//instead of waiting a second. this time only
//wait 1/2 a second per difficulty level
Thread.sleep(500);
}
//print answer
System.out.println("ANSWER:"+answer);
//ask if they want to play again
String again;
again=JOptionPane.showInputDialog("Play again?");
//if user says yes set cont=true
if(again.equals("yes"))
cont = true;
}
while(cont);
}
}
Edited by Donal Byrne, 24 May 2012 - 05:43 PM.







