2012-10-22 28 views
-1

好吧,我知道這是更多的文字比你想,但我真的無法找到下面的代碼期望「{」錯誤?除了預期未指明的ID錯誤?

#include <iostream> 
using namespace std ; 

int main(void) 
{ 
    int score1, score2; 

    PrintInfo() ; 

    score1 = GetScore(); // Call function GetScore, to obtain a value for score1. 

    if (RangeError()) ; // IF score1 is out of range, print an error message. 
    { 
     cout << "Sorry you entered an invalid score." << endl ; 
    } 
    else // THIS IS LINE 46, THIS IS THE ELSE IT IS TALKING ABOUT 
    { 
     score2 = Getscore ; // Call GetScore a second time, to obtain a value for score2. 

     if (RangeError()); // IF score2 is out of range, print an error message. 
     { 
      cout << "Sorry you entered an invalid score." << endl ; 
     } 
     else // ELSE, using a call to function maximum within a cout 
     {  // statement, print the maximum score. 
      cout << maximum() << endl ; 
     } 
    } 

    return 0; 
} 

問題那裏面有很多的,我知道,但主要問題似乎是周圍還有我的第二個。無論出於何種原因,我不斷收到以下錯誤:

lab05a.cpp:46:錯誤:「前 '其他'

lab05a.cpp預計`}:在全球範圍內:

lab05a.cpp: 46:錯誤:在'else'之前預期不合格id-

我知道這與包圍有關,但是我找不到任何問題!另外:我很抱歉缺少行號,我們沒有使用允許它們的編輯器。我可以添加它們,但爲了簡潔起見,我刪除了大量不相關的文本,添加它們不會爲錯誤提供適當的行號。因此,我將顯示第46行。由於問題似乎並不在其中,因此我刪除了大部分聲明。請幫助我,這是我第一次遇到一個我自己無法解決的問題。

+2

你如果以後你有一個分號。另外,你似乎沒有調用'GetScore()'。 – chris

回答

2
if (RangeError()) ; 
{ 

應該

if (RangeError()) 
{ 
+0

哦,謝謝,那很容易 – Stupididiot

+0

哦,現在我得到原因。非常感謝你。 – Stupididiot

+0

哪裏會更值得推薦呢?我本人從來沒有注意到我自己的錯誤,我會一直傾注我的書和筆記,從未發現它。我現在已經學會了尋找我以前認爲是正確的東西。我能夠完成的唯一的懺悔就是自己回答一些非常可憐的問題 - 在完成這個程序時我將繼續做這件事。 – Stupididiot