Y
Y
Yuri2020-10-28 14:30:41
Mathematics
Yuri, 2020-10-28 14:30:41

How to find the value of an expression?

Given: 5f9955d6ea246468093866.jpeg
Here is my code:

//найти значение выражения
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
  setlocale(LC_ALL, "RUS");
  float X;
  cout << "x = ";
  cin >> X;
  if ((X - 5) / (X * X - 9) < 0) cout << "Корень из отрицательного числа\n";
  else if (X != -1) cout << "Логарифм отрицательного числа\n";
  else if (X * X == 9) cout << "Деление на ноль\n";
  else
  {
    float Y = (sqrt(X - 5 / X * X - 9)) + log((X * X + 2 * X + 1));
    cout << "F = " << Y << endl;

  }
  system("pause");
  return 0;
}

Can you help with correcting errors in the checks? -3.3, -1.5 do not pass from the table for me.
Task 8 if anything.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2020-10-28
@uriy99

Your order of checks is wrong.
First you need to check that the denominator is not zero, and only then that the whole fraction is non-negative.
To check that the logarithm is not taken from a negative number, you need to check exactly this (that the expression under the logarithm >=0). For some reason you check that it is equal to zero.
Also, your expression is incorrect. You need to put the brackets. (sqrt(X - 5 / X * X - 9) will calculate the root of x minus 5 divided by x^x, minus 9 - 3 terms, of which only the second is a fraction. In
total, you need to:
- rearrange the conditions so that the division by 0 was the first
- correct the condition for the logarithm of a negative number
- place brackets in the expression.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question