#2501: 迷一般的輸出


howiecool (小樂)


#include<iostream>
#include<cmath>
using namespace std;
main()

{
       double a,b,c,d,e;
       while(cin>>a>>b>>c)
       {
       d=b*b-4*a*c;                
       if(d<0)
       cout<<"No real root"<<endl;
       else if(d==0)
       cout<<"Two same roots x="<<(-b/a)/2<<endl;
       else if(d>0)
       e=pow(d,0.5);
       cout<<"Two different roots x1="<<(-b+e)/(2*a)<<" , x2="<<(-b-e)/(2*a)<<endl;
      
      
      
      
      
       }
}

我輸入1 3 -10      <=這組是通過的 

再輸入1 0 0     <=輸入這個 會輸出

Two same roots x=0

Two different roots x1=8.40477e-308 , x2=-8.40477e-308

再輸入1 1 1     <=也有問題

請問錯在哪?

為什麼他會額外輸出一串不需要得東西?

實在不知道為什麼耶

請各位幫幫忙

#2504: Re:迷一般的輸出


example (學姊)


#include
#include
using namespace std;
main()

{
       double a,b,c,d,e;
       while(cin>>a>>b>>c)
       {
       d=b*b-4*a*c;                
       if(d<0)
       cout<<"No real root"<
       else if(d==0)
       cout<<"Two same roots x="<<(-b/a)/2<
       else if(d>0)
       e=pow(d,0.5);
       cout<<"Two different roots x1="<<(-b+e)/(2*a)<<" , x2="<<(-b-e)/(2*a)<<endl;
      
       }
}

請在網路上搜尋 if 指令的正確用法

#2505: Re:迷一般的輸出


howiecool (小樂)


感恩感恩

我懂了

謝謝學姐