+ 1
How to make use of the comma separator for cin >>
The result for the below code is as expected if the user input is separated by 1) spaces or 2) a new line. However, it fails if the user input is either 3) not separated by spaces or 4) separated by commas. How could I adjust the code such that it would give the correct output for 4)? #include <iostream> using namespace std; int main() { int a, b; int c, d; cin >> a >> b >> c >> d; double A = a*b; double B = c*d; if (B > A) { cout << "BBB"; } else { cout << "AAA"; } return 0; }
3 odpowiedzi
+ 4
Solus here is the easy way
https://code.sololearn.com/c7RJ375einDq/?ref=app
+ 1
~ swim ~
Thank you so much!
So the dummy char method only works if the input is of a specified, fixed format in accordance to where the dummy char is placed relative to the other input variables.
Just curious, would there be an effective way to allow the computer to recognize "non-fixed inputs"?
That is, it could recognize the input of:
1 2 3 4
1,2,3,4
1,2 3,4
1 2,3 4
etc...
as all of the same thing (grouping the former two together and latter two together)