+ 1
whats wrong in this code???
#include <iostream> using namespace std; int main(); { int a=; int b=; int c=; int d=; int x1=; int x2=; cout << "type a" endl; cin >> a; cout << "type b" endl; cin >> b; cout << "type c" endl; cin >> c; d = (b*b) - 4 * a*c; if (d >= 0) { x1 = -b + (d / d) / 2 * a; x2 = -b - (d / d) / 2 * a; cout << "d =" << d << endl; cout << "x1 =" << x1 << endl; cout << "x2 =" << x2 << endl; } return 0; };
4 Réponses
+ 2
Declare your variables without the equal sign, else it is intended to be an assignement, and need to have a right argument value ^^
+ 2
visph is right...ideally you should give all of the variables a value after declared so you can put 0 of null after the =.
but beware of dividing by zero in your code, you should try/catch that error to avoid the program to break
+ 2
try this code, i changed a few things so go over it
#include <iostream>
using namespace std;
int main()
{
int a;
int b;
int c;
int d;
int x1;
int x2;
cout << "type a"<<endl;
cin >> a;
cout << "type b"<<endl;
cin >> b;
cout << "type c"<<endl;
cin >> c;
d = (b*b) - 4 * a*c;
if (d >= 0)
{
x1 = -b + (d / d) / 2 * a;
x2 = -b - (d / d) / 2 * a;
cout << "d =" << d << endl;
cout << "x1 =" << x1 << endl;
cout << "x2 =" << x2 << endl;
}
return 0;
};
0
It should be work like this..
https://code.sololearn.com/cBFhsMw2h8Se/?ref=app