i am not a good programmer and so i need help. im not asking for you to write the program but need help with it !
i have some coding but cant figure out how to put the rest together !

ok so this is what i have so far. im using netbeansIDE 6.9.1
math game !

i have to create a program that will ask the user for how many questions they want from 1-10.
and also if they want it to be addition, subtraction or multiplication, or a combination of them !

now i have to generate two random numbers from 1-10 ... which i did and use only those two numbers to do the addition, sub and multi !
if they pick 1 for addition then add the numbers an so on !

if they picked 10 for the first question ( how many questions they want) then i have to do the math game 10 times .. i cant figure that out !

now when the user puts in their answer i have to look at it then give the correct answer.
if the answer is correct accept it as correct if wrong then wrong.

at the end give the user the correct answer for the problems !

after all is done ... give the user the percent they got right and percent they got wrong. also if possible give which ones they got wrong and the answer for it !

package work;

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

public class Project
{

    public static void main(String[] args)
    {
       System.out.println("Welcome To The Mathematical Game.");

       byte answer;
       byte answer2;
       int num1 = 0, num2 = 0, correctAnswer, userAnswer;

       Scanner userInput = new Scanner(System.in);
       System.out.print("Please enter the number of questions you want"
                + " from 1 to 10: ");

       do
       {
        answer = userInput.nextByte();
        
        if(answer > 10 || answer < 1)
        {
            System.out.print("Sorry, that number did not work. "
                    + "Please enter a number from 1 to 10: ");
        }
        else
        {
            Scanner userInput2 = new Scanner(System.in);
            System.out.print(" 1 for addition, 2 for subtraction, 3 for multiplication "
                    + "(Please pick a number accompanying the type): ");
            do
            {
                answer2 = userInput2.nextByte();

                if(answer2 < 1 || answer2 > 3)
                {
                     System.out.print("Please enter a valid number: "
                           + "1 for addition, 2 for subtraction, 3 for multiplication: ");
                }
                else
                {
                    Random rnd = new Random();

                    // generate two random numbers
                    num1 = (int)((rnd.nextFloat() * 10 + 1));
                    num2 = (int)((rnd.nextFloat() * 10 + 1));

                    // give the user the two numbers
                    System.out.println("The two numbers are: " + num1 + " and "
                            + num2 + ");

                    // ask the user to do the math
                    System.out.println("If you picked 1 for addition then add"
                            + " the two numbers above, if you picked 2 "
                            + "for subtraction then subtract the second number "
                            + "from the first, and if you picked 3 for "
                            + "multiplication then multiply the numbers.");

                    // the user inputs their answer here
                    Scanner userInput3 = new Scanner(System.in);
                    System.out.print("Please enter the answer: ");

                    userAnswer = userInput3.nextInt();

                    if(answer2 == 1)
                    {
                        correctAnswer = num1 + num2;
                    }
                    else if(answer2 == 2)
                    {
                        correctAnswer = num2 - num1;
                    }
                    else
                    {
                        correctAnswer = num1 * num2;
                    }
                    

                }
            }while(answer2 > 0 || answer2 < 4);

        }
       }while(answer < 1 || answer > 10);
        

    }

}

Recommended Answers

All 3 Replies

if they picked 10 for the first question ( how many questions they want) then i have to do the math game 10 times .. i cant figure that out !

for (i=0; i<10; i++){
  //math game code
}

Also, do your random generators work? I usually add a limit to it, like this:
random = rand.nextInt(5);

for (i=0; i<10; i++){
  //math game code
}

Also, do your random generators work? I usually add a limit to it, like this:
random = rand.nextInt(5);

yes my random generators do work .... they generate from 1-10 only !
i need to do the last part where i would be able to let them know if it was right or wrong and percent they got right !

System.out.println("The two numbers are: " + num1 + " and "
+ num2 + ");

If you didn't noticed, you don't need the end quote or + sign here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.