Quantcast
Channel: DaniWeb Solved Topics
Viewing all articles
Browse latest Browse all 564

Trying to make a grading program loop to start from the beginning

$
0
0

I have a program that is meant to display the total, average, student name and letter grade for a student. I'm almost done writing it but I have no idea how to make it loop so it goes back to step 1 from step 4. Everything I've read on using "while" loops hasn't really been helpful to me with this particular application.

import java.util.Scanner;

public class Averages5 {

 public static void main(String[] args) {

        // variable declaration 

        String name;
        int mark1, mark2, mark3 ;
        int grade = 0;
        int A, B, C, F;

        double average;
        // input
        Scanner input = new Scanner(System.in);
        System.out.println("Enter Your Name");
        name = input.nextLine();

        Scanner marks = new Scanner(System.in);
        System.out.println("Enter The Student's Grades");
        mark1 = input.nextInt();
        mark2 = input.nextInt();
        mark3 = input.nextInt();
        int total = mark1 + mark2 + mark3;
System.out.println("The total of the three numbers is: " + total);

        input.close();
        average = (double) (mark1 + mark2 + mark3) / 3;
        System.out.println("Your average from the three grades is " + average);

        if (average >= 90 && grade <= 100) {
            System.out.println("Your Grade is A");
        } else if (average >= 80 && grade <= 89.99) {
            System.out.println("Your Grade is B");
        } else if (average >= 70 && grade <= 79.99) {
            System.out.println("Your Grade is C");  
        } else if (average >= 0 && grade <= 79.98) {
           System.out.println ("Your Grade is F");
        }
        System.out.println("The Student's name is: " + name);
    }
}

Viewing all articles
Browse latest Browse all 564

Trending Articles