//Bad programming, INITIALIZE. #include #include using std::cout; using std::cin; void forberedelse(); void inmatning(); void utrakning(); char forsta; char andra; float A; float B; float C; float X; float Y; float iY; float X1; float X2; void inmatning(){ cout << "Lösning av andragradsekvation av typen AX²±BX±C\nAX²?\n"; cin >> A; cout << A << "X²±?\n"; cin >> forsta; cout << A << "X²" << forsta << "BX?\n"; cin >> B; cout << "X²" << forsta << B <<"X±?\n"; cin >> andra; cout << "X²" << forsta << B << "X" << andra << "C?\n"; cin >> C; cout << "Lösning av följande ekvation:\n" << A << "X²" << forsta << B << "X" << andra << C << "\n\n"; return; } void forberedelse(){ if (A != 1){ B = (B/A); C = (C/A); A = (A/A); } if (((B/2)*(B/2)) < C && andra == '+') { X = (B/2); X = (X*(1*(forsta == '+' ? -1 : 1 ))); Y = (X*X+(C*(andra == '+' ? -1 : 1))); iY = Y*(-1); Y = sqrt(iY); cout << X <<"±"<< "i" << Y << "\n"; return; } utrakning(); } void utrakning(){ X = (B/2); X = (X*(1*(forsta == '+' ? -1 : 1 ))); Y = sqrt(X*X+(C*(andra == '+' ? -1 : 1))); X1 = X+Y; X2 = X-Y; cout << X <<"±"<< Y << "\n" << "X1: " << X1 << "\n" << "X2: " << X2 << "\n"; return; } int main(){ inmatning(); forberedelse(); return 0; }