看板Programming
标 题Re: [问题] C++ 一元二次方程式的解...
发信站不良牛牧场 (Wed Nov 28 15:50:48 2007)
转信站ptt!ctu-reader!ctu-peer!news.nctu!csnews.cs.nctu!news.cs.nctu!news.ee.
这真是愚蠢的错误, 你基本语法没学好...
if 和 else 之间, 请使用大括号包住....
例:
if (...) {
//... 你的程式码
} else {
//... 你的程式码
}
※ 引述《[email protected] (M*)》之铭言:
: #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
: 先谢谢大家罗(鞠躬)
--
╭──── Origin:
<不良牛牧场> bbs.badcow.com.tw (210.200.247.200)─────╮
│ ↘ Welcome to SimFarm BBS -- From : [140.115.135.250] │
╰◣◣◢ ◢◢《不良牛免费拨接→电话:40586000→帐号:zoo→密码:zoo》 ◣◣◢ ─╯