我一直坚持这个已经在这个问题上创建了一段时间的程序。没有人能真正帮助我。我只是想知道如何使void工作,因为里面的变量无法定义。
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;
}
答案 0 :(得分: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()
语句块中输入&quot;&#39; ,并省略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;
}
}