作者swedrf0112 (M*)
看板Programming
標題[問題] C++ 一元二次方程式的解...
時間Wed Nov 28 13:48:20 2007
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char *argv[])
{
double a,b,c,d,x,y,x1,x2;
y=a*x*x+b*x+c;
cout << "The program will caculate the equation./n";
cout << "Please enter a:";
cin >> a;
cout << "Please enter b:";
cin >> b;
cout << "Please enter c:";
cin >> c;
d=b*b-4*a*c;
if (d>=0)
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
cout << " The answer x1 is " ;
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
cout << " The answer x2 is " ;
else
cout << "There is no answer. ";
system("PAUSE");
return EXIT_SUCCESS;
}
我用Dev-C++ Complier之後他會跑出錯誤
expected primary-expression before "else"
可是我怎麼看都沒有錯...登登XD
先謝謝大家囉(鞠躬)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.211.94.136
推 kaiis:if條件式,多行敘述請加{} 125.225.150.78 11/28 14:15
推 Ecnar:寫程式最好是縮排 124.8.142.211 11/28 20:51
推 liwmewmew:強烈建議找本教學書 先練基本語法的程式 140.127.186.7 12/04 16:11