Results 1 to 2 of 2
Thread: Help with if else statements
- 07-24-2007, 04:06 AM #1
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
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:
The error message i get is with this line :Java 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 "); }*/ } }
and the error message states :Java Code:money = (taxes * hours);
Please help. ThanksJava Code:nub:~/Desktop/JavaStuff Josh$ javac bh.java bh.java:42: variable hours might not have been initialized money = (taxes * hours); ^ 1 error
- 07-24-2007, 07:56 PM #2
Senior Member
- Join Date
- Jul 2007
- Posts
- 130
- Rep Power
- 0
Similar Threads
-
avoiding if statements
By valoyivd in forum New To JavaReplies: 1Last Post: 04-02-2008, 09:08 AM -
Help with actionPerformed Statements
By wco5002 in forum New To JavaReplies: 8Last Post: 03-26-2008, 04:02 AM -
Paper,Scissor,Rock If then Statements
By Alberto in forum New To JavaReplies: 2Last Post: 02-11-2008, 11:18 PM -
How to Execute SQL statements in Spring Framework
By JavaBean in forum Java TipReplies: 0Last Post: 09-28-2007, 12:59 PM -
Problems with packages (import statements)
By ai_2007 in forum Advanced JavaReplies: 1Last Post: 06-29-2007, 11:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks