I want help writing a flow chart for a program I wrote.
I want help writing a flow chart for a
math game which generates two random numbers no greater than 50, then asks the user for the
division of them. The Game then keeps asking if they want to play until
they enter n. After that, the program prints the amount of wrong answers
and total questions.
import java.util.*;
public class MathGame {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
//creates a new scanner object
Random rand= new Random();
String yes_or_no="yes";
int wrong_answers=0;
//reads and counts the wrong answers
int total_answers=0;
//reads and counts the total answers
float user_answer=0;
while (!yes_or_no.equals("n"))
//the stopping condition is "n"
{
float n=rand.nextInt(50)+1;
float m=rand.nextInt(50)+1;
System.out.println("The First Random Number Is: "+n);
//program prints a random number
System.out.println("The Second Random Number Is: "+m);
//progran prints another random number
System.out.println("Divide Both Numbers Then State The Answer: ");
//program asks the user to divide both numbers and input the answer
user_answer=sc.nextFloat();
//program reads and stores the answer
if(user_answer!=(n/m)){
System.out.println("Wrong Answer!");
//if user inputted the wrong answer, program prints that its wrong
System.out.println("The Correct Answer Was: "+(n/m));
//program then reveals the correct answer
wrong_answers=wrong_answers+1;
total_answers=total_answers+1;
}
else{
System.out.println("You Got It Correct!");
//If user inputs the correct answer, program will print it is correct
total_answers=total_answers+1;
}
System.out.println("Enter Y To Continue and N To Stop");
//program tells user if they want to stop, enter N, if not, enter Y
yes_or_no=sc.next();
System.out.println(yes_or_no);
}
System.out.println("Wrong Answers: "+wrong_answers);
//program prints the number of wrong answers the user had
System.out.println("Total: "+total_answers);
//program prints the total number of answers
}
}
Step by step
Solved in 2 steps with 1 images