Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

# Not sure how to get this code to work.

WeiJie Lim
Ranch Hand
Posts: 92
What I am planning to do here is to calculate the tax (7%) of a product given its name. I declared 2 variables milk and corn.

I can't get the program to 'remember' the value of the variable assigned to it ..

Jeff Verdegan
Bartender
Posts: 6109
6
It's not really clear what your problem is. If it's that you're trying to turn the user's input "milk" into the local variable milk, you can't do that directly. You can do something like:

This approach is not scalable or flexible though. Without knowing what your exact assignment is, or what you're learned so far and are allowed to use, or what concept is being tested here, it's hard to advise any particular approach.

WeiJie Lim
Ranch Hand
Posts: 92
Oh, sorry for not being able to express my query accurately =/

The actual question is " Assuming that you are asked to calculate the GST ( 7% tax) of a product given the price. The formulae would be : gst*0.07.

Jeff Verdegan
Bartender
Posts: 6109
6
WeiJie Lim wrote:Oh, sorry for not being able to express my query accurately =/

The actual question is " Assuming that you are asked to calculate the GST ( 7% tax) of a product given the price. The formulae would be : gst*0.07.

That doesn't really clarify what particular problem you're having though.

Winston Gutkowski
Bartender
Posts: 10417
63
• 2
Jeff Verdegan wrote:
WeiJie Lim wrote:The actual question is " Assuming that you are asked to calculate the GST ( 7% tax) of a product given the price. The formulae would be : gst*0.07.
That doesn't really clarify what particular problem you're having though.

And it isn't actually a question either.

@WeiJie: programming is NOT coding. Before you write a line of Java code you should plan what you want to do.

My advice: write down the steps you need to accomplish your task in detail, and in English (or your native language); and do it with your computer turned OFF.

You will never be able to code a solution until you understand the problem.

Winston

Jeff Verdegan
Bartender
Posts: 6109
6
• 1
In addition to what Winston says, when you do start coding, start small. Start as small as you need to to get it to compile and run. Maybe that means you start with:

and after that you add just enough code to calculcate the tax on a hardcoded value. And once you get that working, you move on to taking user input or summing up totals or whatever else you need to do. But at each step, you start with a working program and add just a little bit to it and get that program working before moving on. Don't be afraid to write separate, small, throw-away programs to test a concept by itself, without the clutter of the other stuff you've done so far. I've been programming professionally for possibly longer than you've been alive and I still do that all the time.

Campbell Ritchie
Sheriff
Posts: 48985
60
Ryan McClain,
Your post was moved to a new topic.

WeiJie Lim
Ranch Hand
Posts: 92
Thanks all for the replies. I greatly appreciate them =) .

I realised I may have misinterpreted the question.

Here's what I got after I spent some time jotting down my plans .. Should be correct I guess haha.