0

Why is it not working

#include <iostream> using namespace std; int main() { string a; int b,c; cin>>a; cin>>b; cin>>c;} if(a=="add"){ cout<<c+b; } if(a=="multiply"){ cout<<c*b; } return 0;

29th May 2018, 3:52 AM
Vikram
Vikram - avatar
13 ответов
+ 6
I was facing issues earlier, I thought this could be the reason, seems like something else.. thanks for correcting.. this helps my learning as well..
29th May 2018, 12:19 PM
Shobikaj
Shobikaj - avatar
+ 5
29th May 2018, 12:20 PM
Shobikaj
Shobikaj - avatar
+ 3
#include <iostream> using namespace std; int main() { string a; int b,c; cin>>a; cin>>b; cin>>c; if(a=="add"){ cout<<c+b; } if(a=="multiply"){ cout<<c*b; } return 0; }
29th May 2018, 4:08 AM
Shobikaj
Shobikaj - avatar
+ 3
Shobikaj Why do you need to ignore?
29th May 2018, 11:38 AM
Timon Paßlick
+ 3
Shobikaj With this input, it doesn't: add 5 3
29th May 2018, 11:46 AM
Timon Paßlick
+ 3
Yes, if it is in space separated it throws an error..
29th May 2018, 12:15 PM
Shobikaj
Shobikaj - avatar
+ 3
Shobikaj This also doesn't: add 5 3
29th May 2018, 12:17 PM
Timon Paßlick
+ 3
Shobikaj Yes. You don't need to ignore.
29th May 2018, 12:20 PM
Timon Paßlick
+ 2
The flower bracket after int main() is closing Free cin >>c which actually should be after return 0;
29th May 2018, 4:07 AM
Shobikaj
Shobikaj - avatar
+ 2
thanks
29th May 2018, 5:11 AM
Vikram
Vikram - avatar
+ 2
Timon Paßlick to ignore new line char. it was throwing an error without it.
29th May 2018, 11:44 AM
Shobikaj
Shobikaj - avatar
+ 2
It's is working now..🙄😶
29th May 2018, 12:18 PM
Shobikaj
Shobikaj - avatar
+ 1
Also, since your using string you need to ignore cin. Please find the modified code. https://code.sololearn.com/cNbE7UEx4t4o/?ref=app
29th May 2018, 5:10 AM
Shobikaj
Shobikaj - avatar