我检查了嵌套的 if 语句和右括号......不知道为什么,但在编译时出现“预期表达式”错误。错误发生在这段代码中:else if (secondCourseEnrollCount >= 20)
这是我的代码:
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main()
{
string myName, firstCourseID, secondCourseID, thirdCourseID;
int studentID, firstCourseEnrollCount, secondCourseEnrollCount, thirdCourseEnrollCount;
firstCourseEnrollCount=secondCourseEnrollCount=20;
thirdCourseEnrollCount=17;
cout << "Please Type Your Name: ";
cin >> myName;
cout << "Please Type Your Student ID Number without spaces: ";
cin >> studentID;
cout << "Please Type Your First Requested Course ID: ";
cin >> firstCourseID;
cout << "Please Type Your Second Requested Course ID: ";
cin >> secondCourseID;
cout << "Please Type Your Third Requested Course ID: ";
cin >> thirdCourseID;
// First If Statement Should Come Here
if (firstCourseEnrollCount >= 20)
{
// True Path Here
cout << "The first choice currently has 20 Students, " << myName << endl;
cout << firstCourseID << " is Already at Maximum Enrollment, so you have not been added to the class";
// False Path Here
// Second If Statement Here
else if (secondCourseEnrollCount >= 20)
{
// True Path Here
cout << "The second choice currently has 20 Students, " << myName << endl;
cout << secondCourseID << " is Already at Maximum Enrollment, so you have not been added to the class";
// False Path Here
// 3rd If Statement Here
else if (thirdCourseEnrollCount >= 20)
{
// True Path Here
cout << "The third choice currently has 20 Students, " << myName << endl;
cout << thirdCourseID << " is Already at Maximum Enrollment, so you have not been added to the class";
//False Path Here
else
{
cout << "All Three Courses Have Seats Remaining, " << myName << endl;
cout << "You have been enrolled in " << firstCourseID << endl;
cout << "You have been enrolled in " << secondCourseID << endl;
cout << "You have been enrolled in " << thirdCourseID << endl;
}
}// End 3rd If Statement
}// End 2nd If Statement
}// End 1st If Statement
return 0;
}