+ 2
Im having a problem making my code give in an input
I wrote a code fir example Int main() { Int a,b,c,d Cout<<"Enter a number:" Cin>>a..... In the above code,the cin is not working in my code
11 Respuestas
+ 1
LoaftoPVP It's better for one to use "\n" rather than the endl manipulator for performance reasons.
std::endl is slower since it carries an overhead of several unnecessary function calls
+ 3
It seems the issue is that you have forgotten to put semi-colons after the int value and the cout command.
int main()
{
int a, b ,c, d;
cout<<"Enter a number: ";
cin>>a;
}
This code is a bit better, I hope.
+ 2
Your code is perfectly fine when it's running in a third party software like Visual Studio Code or Visual Studio Community 2019. I'd recommend using these when running code as it has more functions. Also, just a suggestion, try using << endl; at the end of each line instead of using \n. This is just my personal preference, but it's up to you. Once again, your code doesn't have any issues, I just think the playground sometimes doesn't work.
+ 1
Here's the revised code:
#include <iostream>
using namespace std;
int main() {
int a, b, c, d;
cout << "Enter variable A: ";
cin >> a;
cout << "Enter variable B: ";
cin >> b;
cout << "Press 1 for adding two variables." << endl;
cout << "Press 2 for subtracting two variables." << endl;
cin >> c;
switch (c)
{
case 1:
d = a + b;
cout << d;
break;
case 2:
d = a - b;
cout << d;
break;
default:
cout << "Wrong input.";
}
}
I just think that the playground doesn't work that well sometimes.
+ 1
Oh wait, have you tried separating the inputs? Like:
1
2
1
That equals to 3.
Another example:
1
2
1
That equals -1.
+ 1
Try Cxxdroid
0
Sure i did all that but after running the code it just gives...let me put the code
https://code.sololearn.com/c63SlmGUH0Gp/?ref=app
0
True, because im using my android phone kindly recomend the best software to use using andrpid phone or a computer
0
Michael Kamau Your program is okay.
The problem you're describing comes from the fact that sololearn's compiler is not interactive.Hence you need to provide the inputs all at once like this
5 6 1 //5 will be a,6 b and 1 c.
Or
5
6
1
0
Anthony maina what is the best app i can use that has the best compiler if im using an android phone without a computer
0
That is if at all there is