• Post Reply Bookmark Topic Watch Topic
  • New Topic

No carriage return and strange output  RSS feed

 
Clint Tuttle
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code is acting really buggy and I can't figure it out!!! Hopefully, one of you or the teacher can chime in and help me figure it out. When I set my first 'if' statement with a decision based on when to start commission, it prints weird. The thing is if I change the Start value it still does it, statically assign it, it still does it, change the value, it still does it...you get the idea.

I have figured out that while the ( < ) or ( <= ) is being called it will do this until it reaches the ( > or >= ) print statement. AND I've been noticing that it behaves weird when ever I use the ( < or <= ) operator. Even on my assignment. HELP!!!

To make it even more weird it only starts doing it at or above a value of 70000. Below 70000 it formats fine.

WHAT THE ****?!!! (heck) Below Is an example along with the code.
**************************************************************
100200 Ill make calculations here12024.0
105200110200115200120200125200130200 I'll make calculations here too 17902.5
135200 I'll make calculations here too 18590.0
140200 I'll make calculations here too 19277.5
145200 I'll make calculations here too 19965.0
150200 I'll make calculations here too 20652.5
**************************************************************
Take out the ( < or <= ) it works fine AND as you can see once the > or >= is used it formats fine. You can put a higher Sales value in and it formats perfect.
**************************************************************
125300 I'll make calculations here too 17228.75
130300 I'll make calculations here too 17916.25
135300 I'll make calculations here too 18603.75
140300 I'll make calculations here too 19291.25
145300 I'll make calculations here too 19978.75.
..rest of output omitted
***************************************************************

 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like line 15 always prints a number.
The text only gets printed by lines 17 and 18 if a condition is true.
If the conditions are false, the text doesn't get printed.

So look at the conditions controlling the printing of the text and see when they will be true so that text will be printed.

One way to see what is happening is to add an else clause after both line 17 and 18 that prints the value of intTotal:
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
Thank you for using code tags, but you have written your lines too long, which affects the legibility of the code. Don't write your if statements as one line; the condition should be on one line and the statement on a third line surrounded by {} to make four lines. Improves legibility and reduces risk of errors if you add another line to the if. I have had a go at correcting some of those things, so you can see how to do it but not added {}.

Why are you using BigDecimal for counts? If you are counting integer values use ints or longs. If you need counts ≥ 2⁶³ (‍), use BigInteger, and use this as your initial value. Why are you mixing BigDecimal, integer arithmetic, and double arithmetic? Why not use this:-Use this rather than new BigDecimal("0").
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!