2014-02-27 18 views
0

我一直堅持這個程序,我已經創建了一段時間,現在在這個問題上。沒有人真的能夠幫助我。我只想知道如何獲得無效的工作,因爲裏面的變量不能被定義。卡住請幫助。空白未定義標識符

void PoorRating(Questionnaire RatingDetails[], int i){ 
    for(i=0;i<100;i++){ 
     if(RatingDetails[i].Rating >=1 && RatingDetails[i].Rating <=3){ 
     } 
     cout << "Information: " << endl << "Name: " << Customer[i].Title << " " << Customer[i].Surname; 
    } 
} 

int main(){ 
    char AnotherQ; 
    int largestgroup; 
    Questionnaire Customer[100];//set an array 
    int i=0; 
    do{ 
     cout << "Please enter Customer title: "; cin >> Customer[i].Title; 
     cout << "Please enter Customer surname: ";cin >> Customer[i].Surname; 
     cout << "Please Enter Telephone: "; cin >> Customer[i].Telephone;//set to college the customer's telephone number 
     Customer[i].Telephone=ValidateTelephone(Customer,i); //Continues to ValidateTelehpone number operation 
     cout << "Please Enter Group Size: "; cin >> Customer[i].Groupsize; 
     Customer[i].Groupsize=ValidateGroupSize(Customer,i);//Continues to ValidateGroupSize number operation 
     cout << "Please Enter Rating of meal: "; cin >> Customer[i].Rating; 
     Customer[i].Rating=ValidateRating(Customer,i);//Continues to ValidateRating operation 
     cout<<"Do you want to Continue(y/n)? "; cin>>AnotherQ;//Asks if user wants to continue or end program 
     i++; 
    } while(AnotherQ=='y' || AnotherQ=='Y'); 

    largestgroup=FindingLargestGroup(Customer, i); 
     cout << "Largest Group: " << largestgroup << endl;//displays information 

    CounterRating(Customer ,i); 
    PoorRating(Customer,i); 

    system("pause"); 
    return 0; 
} 
+2

的完整代碼是不必要的,當你嘗試你已經離開的時候,你不必擔心會把東西拿出來,它也有同樣的問題。請閱讀http://stackoverflow.com/help/mcve – chris

+0

順便說一句,你提到了你面臨的問題...... –

+2

你有一個拼寫錯誤。完整的錯誤信息會告訴你錯誤發生在哪一行。學習閱讀它。 – stark

回答

0

如果我編譯代碼上ideone with GCC 4.3.2,我收到以下錯誤信息:

prog.cpp: In function 'void PoorRating(Questionnaire*, int)': 
prog.cpp:68: error: 'Customer' was not declared in this scope 
prog.cpp: In function 'int main()': 
prog.cpp:97: error: 'system' was not declared in this scope 

在你的方法

void PoorRating(Questionnaire RatingDetails[], int i){ 
    for(i=0;i<100;i++){ 
     if(RatingDetails[i].Rating >=1 && RatingDetails[i].Rating <=3) { 

     } 
    cout << "Information: " << endl 
     << "Name: " << Customer[i].Title << " " << Customer[i].Surname; 
    } 
} 

你想參考到Customer變量,它在main()中聲明。你可能意思是RatingDetails

至於失蹤system()聲明,包括<stdlib.h>

code compiles修復了上述問題。

編輯:
另外請注意,你可能是指有「評爲」if()語句塊內的輸出,並省略for()循環都:

void PoorRating(Questionnaire RatingDetails[], int i){ 
    if(RatingDetails[i].Rating >=1 && RatingDetails[i].Rating <=3) { 
     cout << "Information: " << endl 
      << "Name: " << RatingDetails[i].Title << " " << RatingDetails[i].Surname; 
    } 
} 
+0

我很欣賞迅速的答案,但我改變了程序,但是上面的代碼。但是現在它似乎忽略了僅顯示1-3的評分,並且在提示時輸入'n'後在最後步驟中導致我中斷。我一直在這個atm上工作。任何意見或提示將不勝感激。謝謝。 – user3361789

+0

@ user3361789這是一個不同的問題!我給了你這個正確的答案,好嗎?在對SO進行另一個問題之前,請使用調試器逐步調試您的程序,以縮小您的邏輯/運行時錯誤的位置。看看我的編輯是否有幫助,雖然... –

+0

你打算有'i'作爲參數BTW? –