Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-24-2007, 09:56 PM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
U haven't put an initial value for hours, maybe u forgot to put an input for it?
Nothing wrong with ur if else, just, u didn't put any input for the hours or any initial value, maybe that's why the error came
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
avoiding if statements valoyivd New To Java 1 04-02-2008 11:08 AM
Help with actionPerformed Statements wco5002 New To Java 8 03-26-2008 06:02 AM
Paper,Scissor,Rock If then Statements Alberto New To Java 2 02-12-2008 01:18 AM
How to Execute SQL statements in Spring Framework JavaBean Java Tips 0 09-28-2007 02:59 PM
Problems with packages (import statements) ai_2007 Advanced Java 1 06-29-2007 01:57 PM


All times are GMT +3. The time now is 11:26 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org