Hello,
I'm attempting a calculator program, but I keep getting cannot find symbol errors, I believe I called everything I needed and initialized the variables, I do not know what's wrong. Here is the code:
import java.util.Scanner;
import java.io.*;
public class Calculator
{
public static void main(String[] args)
{
do
{
Scanner s = new Scanner(System.in);
System.out.println("-Easy Calculator-");
System.out.println("1) Add");
System.out.println("2) Subtract");
System.out.println("3) Multiply");
System.out.println("4) Divide");
System.out.println("5) Exit");
System.out.println("Enter Option: ");
int i = s.nextInt();
System.out.println("First Number: ");
int a = s.nextInt();
System.out.println("Your first number number is " +a);
System.out.println("Second Number: ");
int b =s.nextInt();
System.out.println("Your second number number is " +b);
double result = 0;
switch (i)
{
case 1:
result = a + b;
break;
case 2:
result = a - b;
break;
case 3:
result = a * b;
break;
case 4:
if (b == 0)
{
System.out.println("Cannot Divide By Zero");
break;
}
else
result = a / b;
default:
System.out.println("You have entered a wrong choice");
}
} while(i != 5);
System.out.println("Answer = " +result);
}
}
Here are my errors
C:\Users\Desktop\calculator.java:8: error: class Calculator is public, should be declared in a file named Calculator.java
public class Calculator
^
C:\Users\Desktop\calculator.java:80: error: cannot find symbol
} while(i != 5);
^
symbol: variable i
location: class Calculator
C:\Users\Desktop\calculator.java:83: error: cannot find symbol
System.out.println("Answer = " +result);
^
symbol: variable result
location: class Calculator
3 errors