2016-09-18 38 views
-7

我是新來的C++編程,只是無法弄清楚爲什麼它給了我一個「其他沒有以前如果」錯誤。否則沒有以前如果

class Math { 
    public: 
     void m_syllabus() { 
      string math1; 

      if (math1 == "math"){ 
       cout << "\tHere are the important information for the math syllabus:\n"<<endl; 
       cout << "\tInstructor name: \n" <<"\tDr. Zhong J"<<endl; 
       cout << "\tOffice Hours: \n" <<"\tMonday and Wednesday from 10:30am-11:30am and by appointment"<<endl; 
       cout << "\tContact: \n" <<"\tPhone: 245-9966"<< "\tEmail: [email protected]"<<endl; 
       cout << "\tTextbook: \n" <<"\tPrecalculus, Sullivan, 10th edition"<< endl; 
       cout << "\tGrading: \n" <<"\tTest 1, 2, 3 are 15% each"<< endl; 
       cout << "\tAttendance:\n" <<"\t10% "<< endl; 
       cout << "\tQuizzes:\n" <<"\t25%"<< endl; 
       cout << "\tFinal Exam:\n" <<"\t20%"<< endl; 
       cout << "\tTest 1: 9/21(Wed)"<<endl; 
      } 
     } 
}; 

// the English class 

class English { 
    public: 
     void e_syllabus() { 
      string english1, math1; 
      else if (english1 == "english") 
      { 
       cout << "\tHere are the important information for the english syllabus:\n"<<endl; 
       cout << "\tInstructor name: \n" <<"\tHeather "<<endl; 
       cout << "\tOffice Number & Hours: \n" <<"\tTuesday and Thursday from 11:00am-1:30pm and by appointment @ Flowers Hall: 210"<<endl; 
       cout << "\tContact: \n" <<"\tPhone: x53783"<< "\tEmail: [email protected]"<<endl; 
       cout << "\tTextbook: \n" <<"\tReading the World: Ideas that Matter & The Bedford Handbook"; 
      } 
     } 
}; 

int main() { 
    string math1, english1, computer_science1, philosophy1, us1100_1; 
    math1 = "math"; english1 = "english"; computer_science1 = "computer_science"; 
    philosophy1 = "philosophy"; 
    us1100_1 = "us1100"; 
    cout << "What syllabus do you need?\n"; 
    cin >> math1, english1, computer_science1, philosophy1, us1100_1; 

    Math retrieve_m; 
    retrieve_m.m_syllabus(); 

    English retrieve_e; 
    retrieve_e.e_syllabus(); 

    return 0; 
} 
+3

'else if(english1 ==「english」)'in class English。 –

+0

請修復您的格式,這段代碼非常難以閱讀。 – shuttle87

+0

看看你的「英語」課。 –

回答

1

本身不能有else if

在這部分代碼中,

void e_syllabus() { 
     string english1, math1; 
     else if (english1 == "english") 
     { 
      cout << "\tHere are the important information for the english syllabus:\n"<<endl; 
      cout << "\tInstructor name: \n" <<"\tHeather "<<endl; 
      cout << "\tOffice Number & Hours: \n" <<"\tTuesday and Thursday from 11:00am-1:30pm and by appointment @ Flowers Hall: 210"<<endl; 
      cout << "\tContact: \n" <<"\tPhone: x53783"<< "\tEmail: [email protected]"<<endl; 
      cout << "\tTextbook: \n" <<"\tReading the World: Ideas that Matter & The Bedford Handbook"; 
     } 

Zooming you have;

else if (english1 == "english") 

實現它會是這樣的正確方法:

if(A == B){ 
    //do something 
} 
else if (C == D){ 
    //do something here 
} 

在你的情況是;

if(A == B){ 
     //do something 
    } 
    else if (english1 == "english") 
    { 
     cout << "\tHere are the important information for the english syllabus:\n"<<endl; 
     cout << "\tInstructor name: \n" <<"\tHeather "<<endl; 
     cout << "\tOffice Number & Hours: \n" <<"\tTuesday and Thursday from 11:00am-1:30pm and by appointment @ Flowers Hall: 210"<<endl; 
     cout << "\tContact: \n" <<"\tPhone: x53783"<< "\tEmail: [email protected]"<<endl; 
     cout << "\tTextbook: \n" <<"\tReading the World: Ideas that Matter & The Bedford Handbook"; 
    } 
相關問題