Jaskiiez Jaskiiez - 1 month ago 13
Java Question

My loop is not continuing with the next step

I have a problem with my loop

public static void me() {
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("##0.00");
int mew = 0;
double mes = 0;
boolean Curve = true;
int cBool = 0;
double cNum = 0;
double mers = 0;
double wmes = 0;

//Input Midterm weight and score
System.out.println("\nMidterm exam:");
System.out.print("\tWhat is its weight (0-100)? ");
mew = input.nextInt();
System.out.print("\tExam Score ");
mes = input.nextDouble();
while (Curve){
System.out.print("\tWas there a curve? (1 for yes, 2 for no) ");
cBool = input.nextInt();
if (cBool == 2)
Curve = false;
else
System.out.print("\tHow much was the curve? ");
cNum = input.nextDouble();
Curve = false;
}

//calculate weighted Midterm score
mers = (mes+cNum);
if (mers > 100)
mers = 100;
wmes = ((mers/100)*mew);
System.out.println("\tWeighted Exam score: " + df.format(wmes));}
}


The problem is when i enter 2 for cBool it will not continue to the next step, however if i enter 1 for cBool then give a number for cNum it will continue with the next step

Answer Source

Have you tried to isolate all the instructions existing in the else block ? From this:

else
System.out.print("\tHow much was the curve? ");
cNum = input.nextDouble();
Curve = false;

TO THIS :

else

{

 System.out.print("\tHow much was the curve? ");
    cNum = input.nextDouble();
    Curve = false;

}