作者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
1F:推 kaiis:if条件式,多行叙述请加{} 125.225.150.78 11/28 14:15
2F:推 Ecnar:写程式最好是缩排 124.8.142.211 11/28 20:51
3F:推 liwmewmew:强烈建议找本教学书 先练基本语法的程式 140.127.186.7 12/04 16:11