Why is this program not working? IS it because it's written in C? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is this program not working? IS it because it's written in C?

This program ran fine on my compiler. Why isn't it working here? This program is supposed to print out the 2nd smallest number. But in here, the program ends with NO OUTPUT. Is this because I wrote it in C? [Note: I wrote it in C because some other SoloLearn user was asking for this program in C.] https://code.sololearn.com/c8ioyKvlHUwQ/?ref=app

6th Dec 2017, 12:24 PM
1604064_Sharif
1604064_Sharif - avatar
5 Answers
+ 7
@1604064_Sharif Well, There is a nice shortcut available on Sololearn to get scanf working. The compiler usually writes all data read by cin to an internal buffer, and scanf can read from that. So, just add this after the header includes, and your program runs perfectly fine: #define __C_CODE__ cin>> // Well, you could name it anything, but since it's a C code, this name is most suited to the task. Also, if you don't want to do this, Sololearn even has its own C Playground now, but its accessible only from the website, not the app. To use it, see this thread. https://www.sololearn.com/discuss/904240/?ref=app
6th Dec 2017, 12:47 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 6
Sorry, there isn't any alternative to system("cls") as cls is a windows specific command and the compiler here does not have access to the server's C drive. You may try printing a lot of spaces but that will probably return a 'Time Limit Exceeded'. And besides, when you need to take all inputs at once, possibilities of interactive text games are considerably reduced. Perhaps even the developers hate non-web languages...
6th Dec 2017, 12:56 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 2
Full Gamer, as I mentioned, I was writing this code as an answer for some other SoloLearn user who wanted this code in C. So... I really shouldn't use cin.
6th Dec 2017, 12:58 PM
1604064_Sharif
1604064_Sharif - avatar
+ 1
Too sad. 😢 Why is the Code playground for C++ so bad when JS/CSS Code playground is good? I mean, you can implement graphics and animation in JS/CSS. But you can't even implement some basic functions in C++ (scanf, system("cls") etc.)
6th Dec 2017, 12:34 PM
1604064_Sharif
1604064_Sharif - avatar
+ 1
How about system("cls")? I can probably survive without scanf in most cases (by using cin). But I CAN'T survive without system("cls"); Actually, I was trying to make a simple turn based game with animation using cout. But since I can't clear the screen on Code Playground, I am pretty sure if I post it here, it will work pretty bad.
6th Dec 2017, 12:43 PM
1604064_Sharif
1604064_Sharif - avatar