Message from @What Would Jack Conte Do?
Discord ID: 620849564118941707
@Tero that's how you print in c++
And take input
In C++ the '>>' and '<<' indicator data flows with iostream
ok
why's it returning wrong results if not bitshifting then
Why use '+=' here @What Would Jack Conte Do? ?
I don't get the point of the cout in the function
Hmm, that could be something, nesting Couts in the return sequence
Why not ```return x;```?
He's already imported the cmath library, so why didn't he use the pow() function?
both good questions
so apparently the int-returning function square with no return statement results in undefined behaviour
sure do love C/C++
Okay so definitely swap the function to
```int square(int x)
{
x *=x;
return x;
}```
TIL this is a thing https://www.onlinegdb.com/online_c++_compiler
Oh yeah that's super useful
Saves me the trouble of having to unpack Visual Studio's doodads
Saves me the trouble of SSHing
well its an excercise to replicate multiplication without multiplying, like what was done in ancient times
kinda stupid tbh
Ah, then you need some kind of if loop to iterate the value to it's square
Because right now
x += x; only works for squaring 2
😅
What I'm thinking of is something like the 2nd example on this page https://www.techiedelight.com/find-square-number-without-using-multiplication-division-operator/
```c
int findSquare(int num)
{
// convert number to positive if it is negative
num = abs(num);
// stores square of the number
int sq = num;
// repeatedly add num to the result
for (int i = 1; i < num; i++)
sq = sq + num;
return sq;
}```
the problem is that his `square(int x)` was not returning a value
the compiler should be giving a warning about this
i guess we figured that out already
yep
but why not square by just multiplying the numbers? its much more efficient than the iterative approaches
He added it's part of the coding prompt to do it without multiplying
ahhh
This is coding homework, don't you know?
You have to reinvent the wheel first before we can get to basic array declarations
been a while since ive had to do that haha
muh palindrome detection function
reverse a string in place
Reinvent Bubble Sorting
implement quick sort
tedious sometimes but i do think these fundamentals are important