Reputation: 13
I am trying to create a program that outputs the grade the user needs in order to get a grade in a class when asked for certain data. Essentially a Final Exam Calculator. It asks for the user to input their current grade, the grade wanted, and the weight of the exam. I know it's been done before but I need this for my semester project and I don't want to copy someone else's work.
public static void main(String[] args) {
Scanner in =new Scanner(System.in);
double g,r,w,f;
System.out.println("Enter your current class grade *Ex. 98* : ");
g = in.nextInt();
System.out.println("Enter your required class grade *Same format*: ");
r = in.nextInt();
System.out.println("Enter the weight of your Final Exam *Same format*: ");
w = in.nextInt();
f = (r - (100 - w) * g)/w;
System.out.println("The grade you need on your final exam is: " + f +"%");
}
I know that the equation works because I tested it with a calculator, but I need the output to be a percentage. g, r, and w need to also be percentages but I don't know how to write an equation that works with percentages entered by the user.
When I ran the program with g=75, r=80, and w=40, it outputs 75.875% when the answer should have been 87.5%.
Upvotes: 0
Views: 239
Reputation: 1442
Based on the numbers that you have provided, I assume that you mistyped the value of w as '4-' instead of 40
Your arithmetic is incorrect.
The correct equation is :
f = (100 * r - (100 - w) * g)/w;
Upvotes: 1