Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Assignment problem for school  RSS feed

 
Chris McBurn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


can someone please help me with this
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris McBurn wrote:
can someone please help me with this


Do you have a specific question/issue/concern that you are addressing?


[EDIT: Oh I see. You are asking about a compiler error message. Hint. The "=" and the "==" operators are two different operators]

Henry
 
Chris McBurn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I GOT IT. thanks mate.
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for trying to UseCodeTags (that's a link) but you didn't quite get it. The code goes between the tags. I often just highlight the code and press the code button.
 
Liutauras Vilda
Marshal
Posts: 4637
316
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Chris, I'd suggest you to re-think your problem and the method you have constructed (topUp). Such a method I'd expect to see with boolean return type. And the logic would be:

2. I'm not sure you fixed the issue Henry pointed out, but never again write "while (ok == false)" or while (ok == true) as it is error-prone, where it is easy enough to make a mistake. Change to "while (ok)". Of course we could debate if variable name "ok" is good or not, but mostly of the guys probably would say latter. So, you could try to think a better name for the situation.
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never use == false or == true, which are not only error‑prone (you have fallen into that trap yourself) but also poor style.
Not
while (b == true) ...
but
while (b) ...
Not
while (b == false) ...
but
while (!b) ...
The local variable never used warnings tell me you are using Eclipse (probably at too early a stage in your career) and you have yet to work out how much of what it tells you can be ignored You might do well to print those messages and forget about the return type and change that method to void type.
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A boolean return type as Liutauras suggests is a good alternative.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!