Message from @What Would Jack Conte Do?

Discord ID: 620849258806902794


2019-09-10 04:02:20 UTC  

seeing all these double >> around are you sure you're not bitshifting something?

2019-09-10 04:02:32 UTC  

i don't actually know C++ though

2019-09-10 04:06:32 UTC  

@Tero that's how you print in c++

2019-09-10 04:06:37 UTC  

And take input

2019-09-10 04:06:48 UTC  

In C++ the '>>' and '<<' indicator data flows with iostream

2019-09-10 04:06:48 UTC  

ok

2019-09-10 04:07:06 UTC  

why's it returning wrong results if not bitshifting then

2019-09-10 04:07:08 UTC  

Why use '+=' here @What Would Jack Conte Do? ?

2019-09-10 04:07:20 UTC  

I don't get the point of the cout in the function

2019-09-10 04:08:09 UTC  

Hmm, that could be something, nesting Couts in the return sequence

2019-09-10 04:08:23 UTC  

Why not ```return x;```?

2019-09-10 04:11:43 UTC  

He's already imported the cmath library, so why didn't he use the pow() function?

2019-09-10 04:12:15 UTC  

both good questions

2019-09-10 04:14:10 UTC  

so apparently the int-returning function square with no return statement results in undefined behaviour

2019-09-10 04:14:30 UTC  

sure do love C/C++

2019-09-10 04:17:08 UTC  

Okay so definitely swap the function to
```int square(int x)
{
x *=x;
return x;
}```

2019-09-10 04:17:41 UTC  
2019-09-10 04:18:13 UTC  

Oh yeah that's super useful

2019-09-10 04:18:17 UTC  

Saves me the trouble of having to unpack Visual Studio's doodads

2019-09-10 04:18:37 UTC  

Saves me the trouble of SSHing

2019-09-10 05:13:18 UTC  

well its an excercise to replicate multiplication without multiplying, like what was done in ancient times

2019-09-10 05:13:20 UTC  

kinda stupid tbh

2019-09-10 05:14:30 UTC  

it squares a value entered

2019-09-10 12:29:23 UTC  

Ah, then you need some kind of if loop to iterate the value to it's square

2019-09-10 12:29:32 UTC  

Because right now

2019-09-10 12:29:45 UTC  

x += x; only works for squaring 2

2019-09-10 12:41:54 UTC  

😅

2019-09-10 12:43:19 UTC  

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/

2019-09-10 12:44:58 UTC  

```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;
}```

2019-09-10 12:46:39 UTC  

the problem is that his `square(int x)` was not returning a value

2019-09-10 12:47:31 UTC  

the compiler should be giving a warning about this

2019-09-10 12:49:44 UTC  

i guess we figured that out already

2019-09-10 12:50:11 UTC  

yep

2019-09-10 12:51:38 UTC  

but why not square by just multiplying the numbers? its much more efficient than the iterative approaches

2019-09-10 12:51:58 UTC  

He added it's part of the coding prompt to do it without multiplying

2019-09-10 12:52:30 UTC  

ahhh

2019-09-10 12:53:22 UTC  

This is coding homework, don't you know?

You have to reinvent the wheel first before we can get to basic array declarations

2019-09-10 12:53:31 UTC  

been a while since ive had to do that haha

2019-09-10 12:56:51 UTC  

muh palindrome detection function

2019-09-10 12:57:05 UTC  

reverse a string in place

2019-09-10 12:57:17 UTC  

Reinvent Bubble Sorting