user4348046
user4348046

Reputation:

GPA number to GPA letter program. Not sure why it doesn't work

package gpatogradecalculator;

import java.util.Scanner;

public class GPAtoGradeCalculator {

    public static void main(String[] args) {
        // TODO code application logic here

        double GPA = 0.0;

        Scanner response = new Scanner(System.in);

        System.out.println("Please enter your GPA: ");

        GPA = response.nextDouble();

        if(GPA >= 3.5); {
            System.out.println("Your GPA is an A.");


    }   else if(3.0<=GPA && GPA<3.5); {
            System.out.println("Your GPA is a B.");


    }   else if(2.5<=GPA && GPA <3.0); {
            System.out.println("Your GPA is a C.");

    }
        if(GPA < 2.5); {
            System.out.println("You are failing.");
    }

      } // end main

} // end class

Can anyone tell me why this wouldn't work? I don't even know where to begin to fix it. It says that my else lines are without an if, but the if is right above them...

Upvotes: 1

Views: 71

Answers (4)

Manojkumar Khotele
Manojkumar Khotele

Reputation: 1019

Remove ; after conditional statement.

Upvotes: 2

Logan
Logan

Reputation: 1794

Don't put semicolons after each if.

Upvotes: 0

RobP
RobP

Reputation: 9522

Remove the semicolon in if(GPA >= 3.5); { and similar if statements.

Upvotes: 2

Kick Buttowski
Kick Buttowski

Reputation: 6739

get rid of all ; after if () or better sense conditional statement

for example :

if(GPA < 2.5); {
        System.out.println("You are failing.");
}

change to

if(GPA < 2.5) {
        System.out.println("You are failing.");
}

do the same process for other if statement as well

Upvotes: 2

Related Questions