View Single Post
  #1 (permalink)  
Old 07-24-2007, 06:06 AM
zoe zoe is offline
Member
 
Join Date: Jul 2007
Posts: 40
zoe is on a distinguished road
Help with if else statements
Hello, I started writing java. I have the first and second steps done (well, i cannot get the program to loop if the user says yes, and I'm also having problems with the if/else statements)
Here is my code:
Code:
public class bh { public static void main (String agrs[]) { double salary, total, tax, taxes, money; int hours; char answer; System.out.print("Enter salary per hour: "); salary = DummiesIO.getDouble(); System.out.print("Enter tax as a percent (eg. .30): "); tax = DummiesIO.getDouble(); if (tax >= .0 && tax <= 1.0) System.out.print("Enter number hours worked: "); else System.out.print("Invalid Entry. Please enter a number between .0 and .90 : "); tax = DummiesIO.getDouble(); System.out.print("Enter tax as a percent (eg. .30): "); tax = DummiesIO.getDouble(); { if (tax >= .0 && tax <= 1.0) { total = (salary * tax); taxes = (salary - total); money = (taxes * hours); System.out.print("You have made: $ "); System.out.print(money); } else System.out.print("Invalid Entry. Please enter a number between .0 and .90 : "); tax = DummiesIO.getDouble(); } /*System.out.print("Do you want to calculate more hours? (Yes / No): "); reply = DummiesIO.getChar(); if (reply = "Yes") { System.out.print("Enter salary per hour: "); salary = DummiesIO.getDouble(); System.out.print("Enter tax as a percent (eg. .30): "); tax = DummiesIO.getDouble(); System.out.print("Enter number hours worked: "); hours = DummiesIO.getInt(); System.out.print("Enter tax as a percent (eg. .30): "); tax = DummiesIO.getDouble(); total = (salary * tax); taxes = (salary - total); money = (taxes * hours); System.out.print("You made : $"); System.out.println(money); } else { System.out.print("Thank You. Bye "); }*/ } }
The error message i get is with this line :
Code:
money = (taxes * hours);
and the error message states :
Code:
nub:~/Desktop/JavaStuff Josh$ javac bh.java bh.java:42: variable hours might not have been initialized money = (taxes * hours); ^ 1 error
Please help. Thanks
Reply With Quote
Sponsored Links