Hi guys i'm new to the world of programming and have been watching some videos on youtube by thenewboston to get to know Java. In one of his tutorials he shows you how to make a basic calculator but i wanted to improve it by adding the option to choose which operation you want to perform. However not being familiar with code i cannot think of a way to put it so that it is error free.I do also have a seperate class file which coresponds with the second paragraph.The errors appear in the if statements because of the characters * / - +. I am currently using eclipse to write my code as it is very useful for showing you your mistakes. Thanks in advance. Code:
Scanner tut7 = new Scanner(System.in);
double fnum, snum, answer;
System.out.println("Enter First Number Please:");
fnum = tut7.nextDouble();
System.out.println("Enter Second Number Please:");
snum = tut7.nextDouble();
Scanner opinput = new Scanner(System.in);
Operation OperationObject = new Operation();
System.out.println("Enter What Operation You Want to Perform: ");
String oper = opinput.nextLine();
OperationObject.calc(oper);
if (oper = * ){
answer = fnum * snum;
System.out.print("The Answer is: ");
System.out.println(answer);
}else{
if (oper = / ){
answer = fnum / snum;
System.out.print("The Answer is: ");
System.out.println(answer);
}else{
if (oper = + ){
answer = fnum + snum;
System.out.print("The Answer is: ");
System.out.println(answer);
}else{
if (oper = - ){
This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia!
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.