This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Cloud Application Architecture Patterns: Designing, Building, and Modernizing for the Cloud and have Kyle Brown, Bobby Woolf and Joseph Yodor on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Here i am again with if/else statement now

 
Greenhorn
Posts: 23
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I am still struggling with the control statements in my program., and I am now getting an error on the "main" method . I am lost with both errors. I just don't understand what I am missing. I do appreciate all of the help i have gotten I hope you don't get tiered of me. (smiles) Here is my code





Thanks again for your help.

 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can usually find these types of problems by formatting your code. Here's my attempt. Notice the paucity of braces at the bottom. Also each one of your if statements have the same flaw. Do you recognise it?
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, having a member variable yield and a local variable yeild (spelling error) is what they call a "bug waiting to happen" if it isn't already
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check your semi-colons.
 
Michael Humphreys
Greenhorn
Posts: 23
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tom I have looked and looked at this code till I am blue in my face....I can not for the life of me figure out what it is. and I didn't conceder your other point yet I have to figure out this if/else statement. It is my next step tho. Thank you for your comments Tom.
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One problem is you have an extra brace at line 38.
 
Michael Humphreys
Greenhorn
Posts: 23
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Tom I found thew extra brace. I took a look at the semi-colons and I have one for each statement so am I to assume that I don't need one or more???
Thank you again
Michael
 
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's one of your if-statements:

It says "If yield-cost1 is equal to 0, then don't do anything".

I seem to recall posting this before, though. Was that on one of your threads? Anyway go off and look at some example code written by other people. A tutorial, for example. Does that other example put a semicolon in that position?
 
Ranch Hand
Posts: 67
Mac Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Michael,

You needed to remove extra un imp commas after if and else statements & before the if block starts with an open curly brace. and some extra ending curly braces.
apart from that, here is the code you may need :

 
Michael Humphreys
Greenhorn
Posts: 23
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I want to ask a question of etiquette on a forum. Should I keep this thread going as I sill have questions in regards to this program although some issues have been solved Others come up as a consequence of those we have talked about already. I guess what I am asking is should i start a new thread for each new issue or continue this thread and add new issues as they come up. Thanks for all the help so far.
Michael
 
Marshal
Posts: 80874
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest you keep this thread for questions arising from previous questions. It is a bad idea to have two threads about the same thing.

Beware of long lines in code tags; they are difficult to read. Use space not tab for indentation; if you have a decent text editor (eg NotePad2, NotePad++, jEdit) you can set an option to convert a tab to 4 spaces.
 
Campbell Ritchie
Marshal
Posts: 80874
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Beware: you have a local variable called yield and one called yeild. You are only using one, so should delete the other.
 
Michael Humphreys
Greenhorn
Posts: 23
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I would like to thank Dhruva,Paul,and Tom for their help on this issue. I have spent some time and worked out all the issues that we have talked about so far. I sill have one issue remaining. As the program runs it is supposed to evaluate the first "if then else" flow control. If the statement is true then print 0.00. If false move to the next control flow statement and evaluate the "if-then-else" If true print Profit2. If false move to the next statement and print loss.

Now when I run the program all works until i have a "loss" which causes the second control flow statement to print a negative amount for profit2, instead of moving on to the third flow control statement and printing a loss. If you would like to see the code here it is followed by the output.


OUTPUT:

Number Of Chickens =110
Number Of Hens = 100
Number Of Eggs Laid = 3300
CostOf Feed =400.0
Profit = -56.25
You Made A Profit. Way To Go!!!

Once again thanks for all the help.

Michael
 
Campbell Ritchie
Marshal
Posts: 80874
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried to improve your indentation; incorrect indentation makes code hard to read and risks errors with {} not being matched.
Never write == true. Just delete all the == trues in your code.
Never write == false. Change if (b == false) to if (!b) . . . Remember you may bneed () after the ! to maintain precedences
You have one else if followed by {}. Why are you using an empty block?
You are using == 0.00. Remember you may never reach 0 using floating-point numbers because of their inherent imprecision.
 
Campbell Ritchie
Marshal
Posts: 80874
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You still need to check the spelling of yield and yeild.
 
Michael Humphreys
Greenhorn
Posts: 23
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Hey thanks Campbell I got it you gave some great pointers. One thing I have learned is that I have to READ more closely. I am making stupid mistakes. Any way here is the code:

 
Campbell Ritchie
Marshal
Posts: 80874
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
You seem to have a != false in there somewhere; you should delete that as it does nothing at all.
Rather than yield - cost == 0, try yield == cost. As I said earlier, you may not get that exactly, because of imprecisions in floating-point arithmetic, so try
if (Math.abs(yield - cost) < 0.005) . . .
Your breakEven in that case ought to be 0; since you only use the breakEven value in that single if block, you may be able to dispense with it and simply write 0. Note you won't get 0.00 printed unless you use a special instruction. There are several possible instructions, of which printf( . . . %.2f . . . ) might be the easiest.

That means you are allowing up to ½ cent as a margin for errors and still regarding the profit as zero.
 
Michael Humphreys
Greenhorn
Posts: 23
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Happy New Year Everyone!!

I have read all of your comments, thanks again Campbell, and came up with a working copy of code. (Campbell, I haven't addressed the issue with the Break even point yet but that will be my next refinement.) I have learned a lot from you all. TY Here is my code:

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic