java - Sum of integers in an array and multiplying integer by 1.5 -
i having issue getting sum of integers in array , issue getting product of integer * 1.5. code below off new java , have been @ hours , hours. purpose of program enter number of hours worked, each day, 5 days. that, , pay rate, you're supposed output average hours worked, total hours, , total pay. pay should include overtime if there any. appreciated.
string name; string id; int payrate; int[] hours = new int[5]; int avghours; int totalpay; int totalhours = 0; int counter; int overtime = 0; //housekeeping system.out.print("enter employee's name: "); inputstring = input.readline(); name = inputstring; system.out.print("enter employee's id: "); inputstring = input.readline(); id = inputstring; system.out.print("enter employee's pay rate: "); inputstring = input.readline(); payrate = integer.parseint(inputstring); //hourspay counter = 0; for(hours[counter] = 0; counter < 5; counter++) { system.out.print("how many hours did employee work? "); inputstring = input.readline(); hours[counter] = integer.parseint(inputstring); }//endfor for(totalhours = 0; counter < 5; hours[counter]++); { totalhours += hours[counter]; if(totalhours > 40) { overtime = payrate + (payrate / 2); }//endif }//endwhile //print if(counter == 5) { system.out.println(name + " " + id + " $" + payrate + "/hour" ); avghours = totalhours / counter; totalpay = totalhours * payrate + overtime; system.out.println... system.out.println... system.out.println...
@bp_1, re-do code again , pasted below. works. there fundamental error making while coding. compare code mine , see difference.
string name; string id; int payrate; int[] hours = new int[5]; int avghours; int totalpay; int totalhours = 0; int counter; int overtime = 0; scanner input = new scanner(system.in); //housekeeping system.out.print("enter employee's name: "); string inputstring = input.nextline(); name = inputstring; system.out.print("enter employee's id: "); inputstring = input.nextline(); id = inputstring; system.out.print("enter employee's pay rate: "); inputstring = input.nextline(); payrate = integer.parseint(inputstring); //hourspay counter = 0; (hours[counter] = 0; counter < 5; counter++) { system.out.print("how many hours did employee work? "); inputstring = input.nextline(); hours[counter] = integer.parseint(inputstring); }//endfor counter = 0;// reset counter here (totalhours = 0; counter < 5; counter++) { totalhours += hours[counter]; if (totalhours > 40) { overtime = payrate + (payrate / 2); }//endif }//end of loop if (counter == 5) { system.out.println(name + " " + id + " $" + payrate + "/hour"); avghours = totalhours / counter; totalpay = totalhours * payrate + overtime; system.out.println("average hours: " + avghours); system.out.println("total pay: " + totalpay); system.out.println("total hours: " + totalhours); system.out.println("overtime ($): " + overtime); }//end of if
Comments
Post a Comment