+ 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; };

31st Jan 2017, 4:13 PM
Mrlackride
Mrlackride - avatar
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 ^^
31st Jan 2017, 4:22 PM
visph
visph - avatar
+ 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
31st Jan 2017, 5:29 PM
Igor Busquets
Igor Busquets - avatar
+ 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; };
31st Jan 2017, 6:41 PM
david schlemmer
david schlemmer - avatar
14th Sep 2018, 9:39 AM
Дмитрий Игумнов
Дмитрий Игумнов - avatar