why does this code does not work properly | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why does this code does not work properly

code needs to ask for a value then be displayed with function printSomething. then it needs to multiply value by 2. IDK why it returns weird values https://code.sololearn.com/ckF9t1jtjXoj/?ref=app

10th May 2017, 6:33 PM
Santiago Restrepo Serna
Santiago Restrepo Serna - avatar
3 Answers
+ 4
the code is working properly. but when you does not enter a value it choose some random value. try int x=0; or any default value.
10th May 2017, 6:43 PM
MR Programmer
MR Programmer - avatar
+ 2
They are printing next to each other, so when input is 8 printSomething prints 8 and then cout << timesTwo(x) << endl; print 16 without first placing a newline, so you should change printSomething to this: void printSomething(int x) { cout << x << endl; }
10th May 2017, 6:45 PM
Dennis
Dennis - avatar
+ 1
thanks a lot. can't believe it was that simple
10th May 2017, 6:47 PM
Santiago Restrepo Serna
Santiago Restrepo Serna - avatar