#### function c++ How to do input validation?

What’s wrong? How to calculate the logarithm in this function?
How to do input validation?
How do I check for negative exponents?
Why does the function exist when the logarithm is negative, but the code does not recognize it?
I put restrictions on the negative logarithm, but the function for negative values ​​of the logarithm can be calculated.

``````#include <iostream>
#include <math.h>
using namespace std;
int main()
{
float A, B, C, D;
A = 1;
B = 1;
cout << "A = 1" << endl;
cout << "B = 1" << endl;
cout << "Enter C = " << endl;
cin >> C;
cout << "Enter D = " << endl;
cin >> D;
bool IsCorrect = true;
float term1, term2;

if (sin(A) != 0) {
term1 = fabs(B / (sin(A)));
}
else {
cout << "Error, sin = 0. The denominator = 0" << endl;
IsCorrect = false;
}

if (D > 0) {
term2 = (exp(log(D + C * exp(D * log(A))) / 3));

if (log(A) >= 0) {
term2 = (exp(log(D + C * exp(D * log(A))) / 3));
}
else {
cout << "Error, log is negative." << endl;
IsCorrect = false;
}
}
else {
if ((lround(A) - A) == 0) {
if ((lround(A) % 2) == 0)
term2 = (exp(log(D + C * exp(D * log(A))) / 3));
else
term2 = (exp(log(D - C * exp(D * log(A)) / 3)));
cout << "There is no answer." << endl;
IsCorrect = false;
}
}
if (IsCorrect) {
cout << "y = " << term2 + term1;
}
system("pause");
return 0;
}
``````

Source: Windows Questions C++