Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How do I fix this to make the loop questions true?

+1 vote
asked Nov 23, 2020 by THOMAS GUERRA (220 points)

import java.util.Scanner;
import java.lang.Math;

public class Main 
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int QUEST = 0; // accumulator of Questions
        int mcq = 1; //counter of Questions
        int answer; // answer for each question
        int points = 0;
        System.out.print("How many questions do you wanna answer? ");
        QUEST = input.nextInt();
            System.out.println("Q#" + mcq + ")" + (int)(300*Math.random()+1) +  " % "   + (int)(7*Math.random()+2));
            System.out.print("What is your answer: ");
            answer = input.nextInt();
            if(answer==(int)(300*Math.random()+1)  %  (int)(7*Math.random()+2)){
            } else{
        } while(mcq<=QUEST);


Filename: modTutorName

Create a program that prompts the user for a number of modulus math questions that they want to answer. The program will then quiz the player on that number of randomly generated questions of the style:

(random 1-300) % (random 2-7) = ?

For each question the user gets correct they earn a point. After ALL the questions have been asked, the program will display the number of correct answers as well as the percentage of correct answers.

1 Answer

0 votes
answered Nov 23, 2020 by xDELLx (6,200 points)

  1.   System.out.println("Q#" + mcq + ")" + (int)(300*Math.random()+1) +  " % "   + (int)(7*Math.random()+2));
  2.             System.out.print("What is your answer: ");
  3.             answer = input.nextInt();
  4.             if(answer==(int)(300*Math.random()+1)  %  (int)(7*Math.random()+2)){
  5.                 System.out.println("Correct!");
  6.                 points++;
  7.             } else{
  8.                 System.out.println("Wrong!");
  9.             }

One issue that looks obvious is whenever you call random() function ,it will generate a random number. Now on line #1 lets say numerator & denominator evaluate to  100 & 3 whats the gaurantee that line#4 random will generate the same numberator & denominator ??

Please assign the numerator & denominator only once when you compute with with random function.Then use the modulo to on the captured numerator & denominator, as the prob statement requires .


Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.