0
Can u help me
Write a program that inputs two numbers and an operator in main function and passes them to a function. The function applies arithmetic operation on two number on the basis of the operator entered by user using switch statement.
10 Answers
+ 2
I did it
https://code.sololearn.com/c98jag713U9p/?ref=app
on Ruby
0
In which language?
in anyways, You need to add your try here...
Tag the language..!
0
c++
0
What help you need then?
0
public int op(int a , int b , String op){
int cal =0;
switch(op){
case "+":
return a+b;
break;
case value "-":
return a-b;
break;
case value "*":
return a*b;
break;
case value "/":
return a/b;
}
}
0
How do i finish this
0
include cpp header file properly which is required to compile your program then inside main function write statements for user input for two number and declare one more variable which type will be char type and pass these values to op function.
but as your program showing that you have to do it via classes u using public.......?
0
samnew
Is that c++ code or java..
May you copied it from java file..!
C++ case values must be integral type. So you need to convert to int value if you want use strung as case option. it won't support string as cases.
And syntax is :
case value :
But not
case value '+' :
as you using. It's error.
break after return statement is no use.
Convert to c++ code..
You can use a character instead of string in c/c++ case values like :
Sample :
int main()
{
char c = '+'; //check by different operator
switch(c)
{
case '+' : cout<< 2+3;
break ;
default :
cout << "Error";
}
}
0
T u
0
java code that contains colorful outputs