2016-04-18 1 views
-4

私はちょうど初心者の学生です。私の教授は、記録を保持し、20人の生徒のクラスの統計分析を行うためにC++プログラムを作成してほしいと思っていました。 24〜27行目にありますが、わかりません。このコードには何がありますか?

[エラー] '{' トークン

#include <cstdlib> 
    #include <iostream> 
    #include<iomanip> 
    #include<fstream> 
    #include<cstring> 
    using namespace std; 
    struct student { 
    int stnumber; 
    char stname[20]; 
    char sex; 
    float quizz1; 
    float quizz2; 
    float assigment; 
    float midterm; 
    float final; 
    float total; 
    int numberOfitem; 
    }; 
    student st[20]; 
    int itemcount=0; 
    void displayheading(); 
    void Showmax(); 
    void Showmin(); 
    void Sortbyid(); 
    bool Searchduplicate(int); 

    int main() { 
    void displaymenu(){ 

    cout<<"============================================"<<"\n"; 
    cout<<"       MENU         "<<"\n"; 
    cout<<"============================================"<<"\n"; 
    cout<<"  1.Add student records"<<"\n"; 
    cout<<"  2.Delete student records"<<"\n"; 
    cout<<"  3.Update student records"<<"\n"; 
    cout<<"  4.View all student records"<<"\n"; 
    cout<<"  5.Sort student records by ID"<<"\n"; 
    cout<<"  6.Sort student records by Total score"<<"\n"; 
    cout<<"  7.Display average score of a selected student"<<"\n"; 
    cout<<"  8.Display the highest and the lowest scores"<<"\n"; 
    cout<<"  9.Search student by ID"<<"\n"; 
     } 

    void Add() 
    { 

     again: 
     cout<<"Enter student's ID(1-1000):"; 
     cin>>st[itemcount].stnumber; 
     if(Searchduplicate((int)st[itemcount].stnumber)==true){ 
      cout<<"This ID already exists\n";goto again; 
     } 



     cout<<"\n"; 
     cout<<"Enter student's Name:"; 
     cin>>st[itemcount].stname; 
     cout<<"\n"; 
     cout<<"Enter student's Sex(F or M):";cin>>st[itemcount].sex; 
     cout<<"\n"; 
     cout<<"Enter student's quizz1 score:";cin>>st[itemcount].quizz1; 
     cout<<"\n"; 
     cout<<"Enter student's quizz2 score:";cin>>st[itemcount].quizz2; 
     cout<<"\n"; 
     cout<<"Enter student's assigment score:";cin>>st[itemcount].assigment; 
     cout<<"\n"; 
     cout<<"Enter student's mid term score:";cin>>st[itemcount].midterm; 
     cout<<"\n"; 
     cout<<"Enter student's final score:";cin>>st[itemcount].final; 
     st[itemcount].total=st[itemcount].quizz1+st[itemcount].quizz2+ 
    st[itemcount].assigment+st[itemcount].midterm+st[itemcount].final; 



     ++itemcount; 



     } 

    bool Searchduplicate(int id){ 
    bool match=false; 
    for(int i=0;i<itemcount;++i){ 
      if(st[i].stnumber==id) match=true;} 

     return match; 
    } 
    void writedata(){ 

    //save to studentrecords.data file 

     st[0].numberOfitem=itemcount; 
     fstream file("studentrecords.dat",ios::out); 
     file.write((char *)(&st),sizeof(st)); 
     file.close(); 
    } 

    void ViewAll(){ 
      int i=0; 
      displayheading(); 
      while(i<=itemcount){ 
        if(st[i].stnumber!=0){ 
        cout<<left<<setw(5)<<st[i].stnumber<<setw(20)<<st[i].stname<<setw(5)<<st[i].sex; 
        cout<<setw(5)<<st[i].quizz1<<setw(5)<<st[i].quizz2<<setw(5)<<st[i].assigment 
        <<setw(5)<<st[i].midterm<<setw(5)<<st[i]. final<<setw(5) 
        <<st[i].total; 

        cout<<"\n";} 
        i=i+1; 

        } 


      } 



    void Delete(){ 
     int id; 
     cout<<"Enter student's ID:"; 
     cin>>id; 
     for(int i=0;i<itemcount;++i){ 
       if((st[i].stnumber==id)&&(itemcount!=0)){ 


           st[i].stnumber=0; 
           std::strcpy(st[i].stname,"0"); 
           st[i].sex='0'; 
           st[i].quizz1=0; 
           st[i].quizz2=0; 
           st[i].assigment=0; 
           st[i].midterm=0; 
           st[i].final=0; 
           st[i].total=0; 

             } 



       } 

     } 



    void Update(){ 
     int id; 
     cout<<"Enter student's ID:"; 
     cin>>id; 
     for(int i=0;i<itemcount;++i){ 
       if((st[i].stnumber==id)&&(itemcount!=0)){ 

           cout<<"Enter student's Name:";cin>>st[i].stname; 
           cout<<"Enter student's Sex:";cin>>st[i].sex; 
           cout<<"Enter quizz1 score:";cin>>st[i].quizz1; 
           cout<<"Enter quizz2 score:";cin>>st[i].quizz2; 
           cout<<"Enter assigment score:";cin>>st[i].assigment; 
           cout<<"Enter mid term score:";cin>>st[i].midterm; 
           cout<<"Enter final score:";cin>>st[i].final; 
           st[i].total=st[i].quizz1+st[i].quizz2+st[i].assigment+st[i].midterm+st[i].final; 
             } 



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

関数を関数内で定義することはできません。 [機能の作成方法](http://www.tutorialspoint.com/cplusplus/cpp_functions.htm) – NathanOliver

+1

Dudeを再訪する必要があるかもしれません。私はこれを読むことを試みるつもりはない! –

+0

コンパイルエラーまたはランタイムエラーを報告するときは、エラー位置も含めることが重要です(エラーが発生したときに実行されているコード行)。 – lfurini

答えて

6

ローカル関数の定義が許可されていない前に、関数定義はここでは許可されていない、変更:これに

int main() { 
void displaymenu(){ 
} 
} 

void displaymenu(){ 
    // ... 
} 

int main() { 
    // ... 
} 
関連する問題