1. Member
Join Date
Oct 2013
Posts
63
Rep Power
0

Hello, I am trying to make a simple calculator.
I am very new to Java (I started learning around 3 days ago) so bear with me and my lack of knowledge. Sorry and thank you for any help you can provide!

Basically, what I want it to do is when it starts up, it'll greet the user and ask which of the following six functions they want to perform:
addition, subtraction, multiplication, division, exponentiation and square root. Then it should ask about the appropriate number of operands for the function (the user will input a number)
Then it should print the calculation that will be performed, perform it, then print the result.

I am not sure how to accomplish the user input aspect. Do I use "if" statements? I am not sure.
I am really just unsure on how to do all of this.

Using an if statement (else if) would be a good start.

3. Member
Join Date
Oct 2013
Posts
63
Rep Power
0

Originally Posted by Junky
Using an if statement (else if) would be a good start.
Okay, I've worked out how to do the basic operations.
The thing which I'm stuck on is how to get negative numbers to work correctly for the square root operator.
Also, I don't really know how to get the program to perform more than one calculation without restarting the program. Do you know how I might accomplish this?

4. Member
Join Date
Jun 2013
Posts
60
Rep Power
0

Perhaps put the entire program in a while loop and ask if the user wishes to exit. (Y,N)

5. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,647
Rep Power
9

Originally Posted by Propinquity
The thing which I'm stuck on is how to get negative numbers to work correctly for the square root operator.
They don't. However, unless you are going to handle complex numbers, you should simply flag the value as
an error before you take the square root. Also, don't forget about division by zero.

Regards,
Jim

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•