G3ner1c Posted November 8, 2013 Report Posted November 8, 2013 #include<iostream>using namespace std;int main(){int a,b,c;float d,x,y;cout<<"a= ";cin>>a;cout<<"b= ";cin>>b;cout<<"c= ";cin>>c;d=b*b-4*a*c;if(d>0){x=(-b+(SQRTd))/2*a;y=(-b-(SQRTd))/2*a;cout<<"x= "<<x;cout<<"y= "<<y;}elseif(d==0){x==-b/2*a;cout<<"x= "<<x;}elseif(d<0){cout<<"complex";}}Imi spune ca am o eroare la "x=(-b+(SQRTd))/2*a;".Nu inteleg ce greseala este. Quote
SticKyWoX Posted November 8, 2013 Report Posted November 8, 2013 SQRTd -> sqrt(d)si trebuie sa dai #include <math.h> Quote
dekeeu Posted November 8, 2013 Report Posted November 8, 2013 Si mai ai acolo un x==-b/2*a; care e defapt:x=-b/2*a; Quote
G3ner1c Posted November 8, 2013 Author Report Posted November 8, 2013 Asta e ultima #include<iostream>#include<math.h>using namespace std;int main(){int a,b,c;float d,x1,x2,x;cout<<"a= ";cin>>a;cout<<"b= ";cin>>b;cout<<"c= ";cin>>c;d=b*b-4*a*c;Switch(d){case d==0: x=-b\2*a; cout<<"x= "<<x;break;case d<0: cout<<"Solutia e nr complex";break;default:x1=(-b+(sqrt(d)))/2*a; x2=(-b-(sqrt(d)))/2*a; cout<<"x1= "<<x1; cout<<"x2= "<<x2;}}Vreau sa tranform ala de mai sus, sa folosesc case in loc de if.Ce nu e corect? Quote
dekeeu Posted November 8, 2013 Report Posted November 8, 2013 (edited) #include<iostream>#include<math.h>using namespace std;int main(){int a,b,c;float d,x1,x2,x;cout<<"a= ";cin>>a;cout<<"b= ";cin>>b;cout<<"c= ";cin>>c;d=b*b-4*a*c;if(d==0) { x=-b/2*a; cout<<"X="<<x; }else if(d<0) cout<<"Solutia este nr. complex";else{ x1=(-b+(sqrt(d)))/2*a; x2=(-sqrt(d))/2*a; cout<<"x1= "<<x1; cout<<"x2= "<<x2;}}Ce nu e corect?**Nu poti face comparatii in switch gen : a<4 .**Nu poti pune intr-un switch numere reale, doar intregi. Edited November 8, 2013 by dekeeu Quote
G3ner1c Posted November 9, 2013 Author Report Posted November 9, 2013 Va mutlumesc, acum m-am lamurit, nu am folosit calumea switch-u ala. Quote