so I have an assignment and I'm a newbie to programming.
My prof wants to have an output, that when I enter a number, the program will get the square root of that number, then if the answer is in whole number, it will + 1, and if its in a decimal number, it will -1. But the problem is, the if in whole number is working to add 1, but in decimal, its still adding 1. (Sorry for bad english)
For example, I entered 25, the square root of 25 is 5, so in condition, I should add 1 to answer so its 6
If i entered 24, the square root of it is 4.898979486, so it should be 3.898979486, because of its a decimal, the program should -1.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double num, result;
cout << "Enter a number: \n";
cin >> num;
result = sqrt(num);
if (num == 0) {
cout << "\nThe number is in decimal number: " << --result;
}
else {
cout << "\nThe number is in whole number: " << ++result;
}
return 0;
}