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

看板Programming作者時間18年前 (2007/11/28 16:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
這真是愚蠢的錯誤, 你基本語法沒學好... if 和 else 之間, 請使用大括號包住.... 例: if (...) { //... 你的程式碼 } else { //... 你的程式碼 } ※ 引述《swedrf0112.bbs@ptt.cc (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 ◣◣─╯
文章代碼(AID): #17JI0-00 (Programming)
文章代碼(AID): #17JI0-00 (Programming)