Welcome to Dream.In.Code
Become a Java Expert!

Join 149,756 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,484 people online right now. Registration is fast and FREE... Join Now!




gathering the total number from an if else

 
Reply to this topicStart new topic

gathering the total number from an if else, I am trying to declare a variable based on number correct using an if

BudLight412
16 Feb, 2007 - 04:37 PM
Post #1

New D.I.C Head
*

Joined: 28 Jan, 2007
Posts: 16


My Contributions
CODE
//Importing the neccesary commands
import javax.swing.JOptionPane;
import java.util.Random;

public class Jay2
{
  public static void main(String [] args)
  {
  
    int ques1;  //First random number
    int ques2;  // Second random number
    int number = 0;  //How many questions input
    int counter = 1;  //while counter
    int ques_sum;  //sum of the two random numbers
    int response;  //your answer
    int number_right = 1;  //number of questions answered correctly
    int number_total = 0;  //number of questions you wanted
    String input;  //Your input for the two numbers
    String message;  //Correct of Wrong massages
    Random questions = new Random();  //Random number selector
    
    
    
    //Asking how many questions
    input = JOptionPane.showInputDialog("Welcome to Jay's simple addition quiz! \n\nHow many questions would you like?");
    number = Integer.parseInt(input);
    
    while(counter <= number)
    {
      ques1 = (Math.abs(questions.nextInt())%20)+1;
      ques2 = (Math.abs(questions.nextInt())%20)+1;
      ques_sum = (ques1+ques2);
      
      input = JOptionPane.showInputDialog(ques1+ "+" +ques2);
      response = Integer.parseInt(input);
      
      if(response == (ques_sum))
      {
      message =  "Correct!";
      JOptionPane.showMessageDialog(null, message.toUpperCase());
      }
      else
      {
      message = "Wrong!";
       JOptionPane.showMessageDialog(null, message.toUpperCase());
      }
      ++counter;
    }
    number_right = (response==ques_sum);   // THIS IS WHERE I AM GETTING ERRORS, I DONT KNOW WHY
    number_total = number;
    
    JOptionPane.showMessageDialog(null, "You correctly answered "+number_right+" out of "+number_total+" questions correctly. \nYour percentage is: "+number_right/number_total+"%");            
    
    System.exit(0);
  }
}

User is offlineProfile CardPM
+Quote Post

eLliDKraM
RE: Gathering The Total Number From An If Else
16 Feb, 2007 - 04:39 PM
Post #2

Pepè Le Pewn
Group Icon

Joined: 13 Aug, 2005
Posts: 6,565



Thanked: 2 times
Dream Kudos: 225
My Contributions
YOU SIR wrong forum.

I NOW COMMAND AN ADMINISTRATOR TO MOVE THIS
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Gathering The Total Number From An If Else
16 Feb, 2007 - 04:47 PM
Post #3

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,306



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
As you command moved to Java forum.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 06:04AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month