I have written this program in cpp to perform basic calculations on two variables using functions and switch.The program does compile with zero errors,but the answer it gives is false.Please tell me if its a glitch with the code or the program itself is untrue.
Code:
#include<iostream>
using namespace std;
int menu(int x, int y,char choice)
{
switch(choice){
case'A':
cout<<"The sum of "<<x<<" and "<<y<<" is "<<x + y;
break;
case'S':
cout<<"The difference between "<<x<<" and "<<y<<" is "<<x - y;
break;
case'M':
cout<<"The product of "<<x<<" and "<<y<<" is "<< x * y;
break;
case'D':
cout<<"The ratio of "<<x<<" and "<<y<<" is "<<x / y;
break;
default:
cout<<"Invalid Input";
}
}
int main()
{
int a,b;
char choose;
cout<<"Enter the first number:";
cin>>a;
cout<<"Enter the second number:";
cin>>b;
cout<<"Enter your choice:";
cin>>choose;
cin.ignore();
cout<<menu(a,b,choose);
cin.get();
return 0;
}