alienA2 Posted April 17, 2012 Share Posted April 17, 2012 Hi My program is not calculating the wages correctly. Can somebody please tell me why??? /** PayCheck Program* This program computes an employee's wages for the week*/import java.util.Scanner;import static java.lang.System.in;import static java.lang.System.out;class mainPayCheckProg{ public static void main(String args[]) { // create an instance of the class or object payCheckMethods aWage = new payCheckMethods(); Scanner prompt_user = new Scanner(in); double payRate; double hours; double wages; int empNum; double max_hours = 40.0; double overtime = 1.5; out.print("Enter Employee Number: "); empNum = prompt_user.nextInt(); out.print("Enter Pay Rate: "); payRate = prompt_user.nextDouble(); out.print("Enter Hours Worked: "); hours = prompt_user.nextDouble(); if (hours > max_hours) { wages = (max_hours * payRate) + (hours - max_hours) * payRate * overtime; } else { wages = max_hours * payRate; } out.print("Employee Number: "); out.println(empNum); out.print("Pay rate: "); out.println(payRate); out.print("Hours worked: "); out.println(hours); out.print("Wages: "); out.println(wages); }} Link to comment Share on other sites More sharing options...
smiles Posted April 18, 2012 Share Posted April 18, 2012 your program is innocent Is the calculating formula correct ? Link to comment Share on other sites More sharing options...
alienA2 Posted April 18, 2012 Author Share Posted April 18, 2012 your program is innocent Is the calculating formula correct ? According to the C++ book I have yes lol Link to comment Share on other sites More sharing options...
boen_robot Posted April 22, 2012 Share Posted April 22, 2012 Try to be even more explicit with the priority of operations, i.e. wages = (max_hours * payRate) + ((hours - max_hours) * payRate * overtime); And since this example is derived from a C++ book... try to also be this explicit with C++, and see if the result is the same as the intended one. If the result in ++ is different, this means there's some priority handling missing here, and the intended formula is really wages = ((max_hours * payRate) + (hours - max_hours)) * payRate * overtime; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now