int main() { setlocale(0,""); int a,b,c,x; int t = x^2; double x_1,x_2; cout<<"Введите значения :"<<endl; cin >> a; cin >> b; cin >> c; cout << "Значение а = " << a <<endl; cout << "Значение b = " << b << endl; cout << "Значение c = " << c << endl; int count = a*t^2 + b*t + c; double d = b^2 - 4*a*c; if (count >= 0 ) { x_1 = (-b + sqrt(d)) / 2 * a; x_2 = (-b - sqrt(d)) / 2 * a; cout<<"Первый корень = "<<x_1<<endl; cout<<"Второй корень = "<<x_2<<endl; } else { cout<<"Корней нет!"; cout << "А не должно быть равно нулю!"; } system("pause"); return 0; } 

It is closed due to the fact that it is off-topic by MSDN.WhiteKnight , freim , mkkik , aleksandr barakin , 0xdb members on Apr 23 at 5:30 pm .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - MSDN.WhiteKnight, freim, mkkik, 0xdb
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • As @SeniorPomidor pointed out, you have at least an uninitialized variable x , the value of which you are trying to raise to a power in the string int t = x^2; . - ߊߚߤߘ
  • Do you have equation coefficients only integers? - Harry
  • and don't forget that x_2 is actually t ^ 2. therefore, from the positive root you need to calculate the square root (if imaginary numbers are not passed) - Senior Pomidor
  • @Igor oh, on the contrary. t = x_ ^ 2 - Senior Pomidor

3 answers 3

 int t = x^2; 

Suppose there is such a "cap" operator :-), which raises a number to a power. What is t after this line?

https://www.tutorialspoint.com/cprogramming/c_operators.htm

Remove from the code all the lines where the variable t occurs. And change the check to

 double d = b*b - 4*a*c; if (d >= 0) { x_1 = (-b + sqrt(d)) / (2 * a); x_2 = (-b - sqrt(d)) / (2 * a); ... 

Update

Plus, the calculation of the roots of x_1 and x_2 - as in the answer @SeniorPomidor.

  • t is not a known variable, it is a double quadratic equation. - Sagaydak1411 2:53 pm
  • @ Sagaydak1411 However, you use it below to calculate the count . - Igor
  • That's why I don’t see other ways to solve this problem, having come to a dead end, I turned to this site for help - Sagaydak1411

This is a biquadratic equation. It has the form a x ^ 4 + b x ^ 2 + c, but we will use the replacement. let t = x ^ 2. then the equation has the form a t ^ 2 + b t + c

 #include <iostream> #include <cmath> using namespace std; int main() { setlocale(0,""); int a,b,c,x; double x_1,x_2; cout<<"Введите значения :"<<endl; cin >> a; cin >> b; cin >> c; cout << "Значение а = " << a <<endl; cout << "Значение b = " << b << endl; cout << "Значение c = " << c << endl; double d = b^2 - 4*a*c; if (count >= 0 ) { x_1 = (-b + sqrt(d)) / 2 * a; x_2 = (-b - sqrt(d)) / 2 * a; // так как t может быть только положительным числом из-за t=x^2, //то нужно проверить, что корни не отризательные if(x_1 > 0){ int root1 = sqrt(x_1); cout<<"Первый корень = "<<root1<<endl; cout<<"Второй корень = -"<<root1<<endl; } // и второй корень тоже if(x_2 > 0){ int root1 = sqrt(x_2); cout<<"Третий корень = "<<root1<<endl; cout<<"4 корень = -"<<root1<<endl; } } else { cout<<"Корней нет!"; cout << "А не должно быть равно нулю!"; } return 0; } 
  • Remove from the code all the lines where the variables t and count . - Igor
  • yes, thank you for saying - Senior Pomidor

^ Is a bitwise exclusive or . For exponentiation, use std::pow() from the <cmath> header file:

 int t = std::pow(x, 2); 

But an even better solution, since you have integers, will be replacing the squaring by multiplying the number by yourself:

 int t = x * x; 

This will be faster in computation time, and will also not lead to a loss of accuracy with large numbers.

  • one
    int a,b,c,x; int t = x*x; what will be equal to t if x is not initialized? - Senior Pomidor
  • @SeniorPomidor, eh, that's it. And I went further by mistakes. - ߊߚߤߘ
  • not initialized variable x, what to do with it? - Sagaydak1411
  • @Sagaydak1411, I don’t know, this is your algorithm, and only you know what this x means in general. According to the generally accepted notation, I can assume that this is some root of the equation. But how can you use it without first calculating it? - ߊߚߤߘ
  • @SeniorPomidor, ^^^ - ߊߚߤߘ