Hello. This is my first time programming in any language so please excuse my ignorance. I am trying write a program that asks the user to enter any number 3 times . I have assigned a function that takes the number and outputs an answer . After the 3rd number has been entered , the user is asked to guess what function was used to achieve that answer. The user is given 3 attempts to guess this answer , at which time I wan to move on to the next question. I am having trouble with the counter aspect of this program. Thanks for any assistance.
import javax.swing.*;
public class GuessingGameRevised
{
public static void main (String [] arguments)
{
String guess1, guess2, guess3, selection;
String function1 = "2x + 5";
double answer1,answer2,answer3, userselection;
int counter = 1 ;
guess1 = JOptionPane.showInputDialog(null, " Please select a number " );
guess2 = JOptionPane.showInputDialog(null, " Please select a second number " );
guess3 = JOptionPane.showInputDialog(null, " Please select a third number " );
answer1 = Double.parseDouble(guess1);
answer2 = Double.parseDouble(guess2);
answer3 = Double.parseDouble(guess3);
selection = JOptionPane.showInputDialog(null, " You chose " + answer1 + "\nand when inserted into the function equals :\n" + function(answer1) +
" \n\nYou chose " + answer2 + "\nand when inserted into the function equals:\n" + function(answer2)+
" \n\nYou chose " + answer3 + "\nand when inserted into the function equals:\n" + function(answer3) +
"\n\nNow, can you determine what the function is?");
while(!function1.equals(selection))
{
JOptionPane.showInputDialog(null, selection + " is not the correct function.\n\nSorry please try again");
counter++;
System.exit(0);
}
JOptionPane.showMessageDialog(null, "Wow your smarter than Dr. Nii!");
System.exit(0);
}
public static double function(double f)
{
double func;
func = (2*f) + 5;
return func;
}
}