Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

Thread: simple java calculator Help!

1. simple java calculator Help!

im just learning java and im trying to program a multipurpose calculator but i keep running into brick walls. Heres the coding:

Code:
```import java.util.Scanner;

public class dinoremix2{

public static void main (String[] args){
boolean play = false;
String playAgain;
do{

String math;
System.out.println(" Hello! Just type what you want to do! add , multiply , subtract , divide , or quadratic (please dont use caps) ");
String math = scan.nextString;

if (math = add);{
do{
Scanner in = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
System.out.println(" Please Enter Your First Number: ");
int num1 = dinoremix.nextInt();
System.out.println(" Thanks! Please Enter The Second Number: ");
int num2 = dinoremix.nextInt();
int answer = num1 + num2;
System.out.println(" Your answer is: " + answer );

if (math = subtract);{
do{
Scanner in = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
System.out.println(" Please Enter Your First Number: ");
int num1 = dinoremix.nextInt();
System.out.println(" Thanks! Please Enter The Second Number: ");
int num2 = dinoremix.nextInt();
int answer = num1 - num2;
System.out.println(" Your answer is: " + answer );

if (math = divide);{
do{
Scanner in = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
System.out.println(" Please Enter Your First Number: ");
int num1 = dinoremix.nextInt();
System.out.println(" Thanks! Please Enter The Second Number: ");
int num2 = dinoremix.nextInt();
int answer = num1 / num2;
System.out.println(" Your answer is: " + answer );

if (math = multiply);{
do{
Scanner in = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
System.out.println(" Please Enter Your First Number: ");
int num1 = dinoremix.nextInt();
System.out.println(" Thanks! Please Enter The Second Number: ");
int num2 = dinoremix.nextInt();
int answer = num1 * num2;
System.out.println(" Your answer is: " * answer );

if (math = quadratic);{
do{
Scanner in = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
System.out.println(" Please Enter a: ");
double a = scan.nextDouble();
System.out.println(" Please Enter b: ");
double b = scan.nextDouble();
System.out.println(" Please Enter c: ");
double c = scan.nextDouble();
double disc = (b*b)-(4*a*c);
boolean isImag = false;
if (disc == 0){
double fac = (b * -1) / (2 * a);
System.out.println("heres the root" + fac);
}
if(disc > 0) {
isImag = false;

}
if (disc < 0){
isImag = true;
disc = disc * -1;
}
double fac1 = ((b * -1) + Math.sqrt(disc))/(2*a);
double fac2 = ((b * -1) - Math.sqrt(disc))/(2*a);
if (isImag){
System.out.println(fac1 + "i");
System.out.println(fac2 + "i");
}else{
System.out.println(fac1 + "i");
System.out.println(fac2 + "i"); }

System.out.println("Try again? ");
playAgain = in.nextLine();
if(playAgain.equals("yes")){
play = true;
}
if(playAgain.equals("no")){
play = false;
}
}
}```
im missing a set of closing brackets somewhere but i cant find where

• another brick wall: posting in the wrong branch.

this is javascript. you're looking for java

• Users who have thanked xelawho for this post:

Microsuck (02-18-2012)

• You are missing *MANY* closing braces.

Why in the world are you using do, at all?

You also have a fatal error in your if usage:
Code:
`    if (math = add);`
That semicolon there means the condition after the if is NOW COMPLETE.

The code after the semicolon will thus be executed no matter if the if condition is true or false.

KEEP IT SIMPLE!
Code:
```		if (math = add)
{
Scanner in = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
System.out.println(" Please Enter Your First Number: ");
int num1 = dinoremix.nextInt();
System.out.println(" Thanks! Please Enter The Second Number: ");
int num2 = dinoremix.nextInt();
int answer = num1 + num2;
System.out.println(" Your answer is: " + answer );
}
else if (math = subtract)
{
...```
Indenting your code properly would also help you find the missing braces. I counted AT LEAST TEN missing right braces.

•

Posting Permissions

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