Im having a problem making my code give in an input | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

3rd Aug 2020, 7:14 PM
Michael Kamau
Michael Kamau - avatar
11 Answers
+ 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
4th Aug 2020, 6:33 PM
Anthony Maina
Anthony Maina - avatar
+ 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.
3rd Aug 2020, 7:26 PM
Andy Chang
Andy Chang - avatar
+ 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.
3rd Aug 2020, 7:38 PM
Andy Chang
Andy Chang - avatar
+ 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.
3rd Aug 2020, 7:42 PM
Andy Chang
Andy Chang - avatar
+ 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.
3rd Aug 2020, 7:51 PM
Andy Chang
Andy Chang - avatar
+ 1
Try Cxxdroid
5th Aug 2020, 4:54 PM
Anthony Maina
Anthony Maina - avatar
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
3rd Aug 2020, 7:29 PM
Michael Kamau
Michael Kamau - avatar
0
True, because im using my android phone kindly recomend the best software to use using andrpid phone or a computer
3rd Aug 2020, 7:51 PM
Michael Kamau
Michael Kamau - avatar
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
4th Aug 2020, 6:29 PM
Anthony Maina
Anthony Maina - avatar
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
5th Aug 2020, 1:43 PM
Michael Kamau
Michael Kamau - avatar
0
That is if at all there is
5th Aug 2020, 1:43 PM
Michael Kamau
Michael Kamau - avatar