Hello I'm quite new to C++ (Actually moved to C++ from C recently)
So, I was trying to write a C++ program where I intended to read a rational number as p/q so I wrote something like "Cin >> a >> '/' >> 'b;" But it doesn't works and says something like Ambiguous Overload detected.
Any Help?
@AnkitSingh 12
Hello, I think you misinterpreted my question. I was not trying to calculate but rather read a rational number as numerator and denumerator separately. In C I used to do it as,
scanf("%d/%d",&a,&b);
Just don't know how to do it in C++.
Thanks in advance.
#include <iostream>
usingnamespace std;
int main () {
int a, b, sum = 0;
char myChar;
cout<<"Enter first number: ";
cin>>a;
cout<<"Enter / for this operation; "
cin>>myChar;
cout<<"Enter second number: ";
cin>>b;
switch (myChar) {
case'/'":
if (b == 0){
cout<<"Error"<<endl;
}
else
sum = a/b;
cout<<"The sum is: "<<sum<<endl;
break;
default: cout<<"Error! You entered wrong operation!"<<endl;
break;
}
cin.get(); cin.get();
return 0;
This code is not compiler. You may get some error. :))
@ALL:
Well thanks for suggestion guys, but I don't want other alternatives because I already know them, I was just asking whether it is possible to do it that way or not. If you guys know if its possible then do write but now I'm starting to think that it is not. Anyways, thanks for help. And do post if you know the method. THANKS!!