[問題] C++ 一元二次方程式的解...

看板Programming作者 (M*)時間18年前 (2007/11/28 13:48), 編輯推噓3(300)
留言3則, 3人參與, 最新討論串1/3 (看更多)
#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

11/28 14:15, , 1F
if條件式,多行敘述請加{}
11/28 14:15, 1F

11/28 20:51, , 2F
寫程式最好是縮排
11/28 20:51, 2F

12/04 16:11, , 3F
強烈建議找本教學書 先練基本語法的程式
12/04 16:11, 3F
文章代碼(AID): #17JG4bcI (Programming)
文章代碼(AID): #17JG4bcI (Programming)