0

Hello,
i want to write a program that will help an elementary school student to lean multiplication. For this, i use random object to produce two new positive one-digit integers. For this, i have coded this, but then got confused of the scope issue. Here is the code so far:

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

public class CarpimOgretme {
    Random myRandom = new Random(); 
    Scanner input = new Scanner(System.in); 

    public void determine(){ 

    do{
    int num1 = 1 + myRandom.nextInt(11);
    int num2 = 1 + myRandom.nextInt();
    int answer = num1 * num2; 
    int cevap = input.nextInt();
    }while (answer != cevap); 


    }//end method

}//end class

Here, in the while block, it cannot reach answer and cevap, which means 'answer' in my language for your information. How can i reach ? Please help !!

2
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by NormR1
0
import java.util.Random; 
import java.util.Scanner; 

public class CarpimOgretme {
    Random myRandom = new Random(); 
    Scanner input = new Scanner(System.in); 

    public void determine(){ 
    int num1 = 1 + myRandom.nextInt(11);
    int num2 = 1 + myRandom.nextInt(11);
    System.out.println("num1 = " + num1 + "num2 = " + num2 );
    int answer = num1 * num2; 
    int cevap = input.nextInt();

    while ( answer != cevap ){ 
        determine(); 
    }



    }//end method

}//end class
0

I have just added this to my code, but i still could not figure out how to ask the same question till answer is correct ?

0

Try listing the steps in the order the program needs to do them to solve your problem. When you get the logic worked out, then try writing the code.

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

public class CarpimOgretme {
    Random myRandom = new Random(); 
    Scanner input = new Scanner(System.in); 
    public void determine(){ 
    for ( int i = 0; i < 20; i++ ){


    int num1 = 1 + myRandom.nextInt(11);
    int num2 = 1 + myRandom.nextInt(11);
    System.out.println("num1 = " + num1 + " num2 = " + num2 );
    int answer = num1 * num2; 
    int cevap = input.nextInt();
        while ( answer != cevap ){
            System.out.println("Wrong... Try Again."); 
            cevap = input.nextInt();
        }//end while 

        }//end for statement
    }//end method

}//end class

OK. I did it myself. Even though you did not answer, thank you all.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.