I have most of it...I just need the code for where it displays how many the user got correct/incorrect.
Actual Question:
Each time the user enters a slope, the
computer lets him/her know if she is correct or incorrect. If the user is
incorrect, then the program displays the correct answer, before asking
another. Also, the program should keep track of the total number of questions
and the number correct and report this information. Name the program Slope3.
Here is what I have so far:
import java.util.Scanner;
import java.util.Random;
class Loop3 {
public static void main(String args[])
{
int slope = 0;
int count = 0;
int count2= 0 ;
int yInt = 0;
int response = 0;
Scanner scan = new Scanner(System.in);
Random generator = new Random();
String intro = "You will be asked to find the slopes of several lines\n" +
"When you want to quit, type -500 for the value of the slope\n";
System.out.println(intro);
do
{
count = count + 1;
slope = generator.nextInt(20)+1;
yInt = generator.nextInt(20)+1;
System.out.println("What is the slope of the line y = " + slope + "x + " + yInt + "?");
System.out.println("You have tried " + count + " times.");
response = scan.nextInt();
if(response == slope)
{
count2 = count2 + 1;
System.out.println("Yes! you have tried " + count2 + " times");
}
else
{
System.out.println("No, try again ");
}
} while (response != -500);
}
}