0

Deadly question

i have this thing: if(number%10 != 0) return isRoot = true; else return isRoot = false; this thing is in bool function and i have this thing: if(isRoot(number) == true) std::cout << "true"; else std::cout << "false"; and this thing is in main i don't understand why it doesn't outputs anything if it must anyway(all possible situations takes in(if and else)) i can share whole code if you like

12th Sep 2018, 9:30 AM
Oleg Storm
Oleg Storm - avatar
3 odpowiedzi
+ 2
1. The variable number is a dangling pointer, it doesn't point to any address in the memory, so (std::cin >> *number) will generate a compile-time error. In order for it to be assigned a value, it needs to be initialized. 2. Logical error. Cbrt, I suppose, is an abbreviation of cube root, but the body shows that it computes and return the squared, de-referenced parameter. 3. The call to Cbrt doesn't affect it's argument, and it's returned value is not assigned anywhere. 4. Sqrt is redundant, a call to sqrt provides the same result. 5. (isRoot(Sqrt(number)) == true) is redundant, (isRoot(Sqrt(number))) is enough. 6. (return isRoot = true) and (return isRoot = false) are both redundant and bad practice. (return true) or (return false) is enough, and assignment should not be in the same line with return statement. 7. My biased-opinion: Not sure if you're practicing pointer or not, 'cause all the uses of pointers here are unnecessary. There might be other logical errors, but it's hard to assume the purpose of the program from just looking at it. The code below only removes compile-time errors, I'll leave run-time and logical ones to you. https://code.sololearn.com/cb4C5w5Q72iV/#cpp
12th Sep 2018, 11:00 AM
Hoàng Nguyễn Văn
Hoàng Nguyễn Văn - avatar
+ 1
Nguyen, i will check it soon, thanks for your answer
12th Sep 2018, 11:04 AM
Oleg Storm
Oleg Storm - avatar
12th Sep 2018, 9:32 AM
Oleg Storm
Oleg Storm - avatar