2016-04-06 15 views
0

私は学生の情報とマークを管理するプログラムを作成しています。私の問題は、エラーが発生していることです。入力23,26,29,32、および53行のこの範囲に表示されません。誰かが私が間違っていることを示唆することはできますか?エラー入力がこのスコープに表示されない

#include <iostream> 
#include <fstream> 
#include <string> 
using namespace std; 

int main() 
{ 
    system("cls"); 
    system("Project Assignment"); 
    system("colr 0f"); 
    cout << "Please enter choice" <<endl; 
    cout << "1. Input new student" <<endl; 
    cout << "2. Search for student by number" <<endl; 
    cout << "3. Edit an exiting student marks" <<endl; 
    cout << "4. Display all students" <<endl; 
    cout << "5. Exit" <<endl; 

    int choice; 
    cin >> choice; 

    switch (choice){ 
    case 1: 
     input(); 
     break; 
    case 2: 
     search(); 
     break; 
    case 3: 
     edit(); 
     break; 
    case 4: 
     displayAll(); 
     break; 
} 

    void input(); 
    { 
     system("cls"); 
     string fname; 
     string lname; 
     string filename; 
     int mark; 
     int studNum; 

     cout << "Input student first Name:" ; 
     cin >> fname; 
     cout << "Input student last name: "; 
     cin >> lname; 
     cout << "Input student mark: "; 
     cin >> mark; 
     cout << "Input student number: "; 
     cin >> studNum; 
     string studNum2 = to_string(studNum); 
     studNum2.append(".txt"); 

     ofstream newstudent(studNum2); 
     newstudent <<fname <<" " <<lname <<" "<<mark <<" "<<studNum << endl; 
     newstudent.close(); 




    } 
    void search(); 
    { 

    } 
    void edit(); 
    { 

    } 
    void displayall(); 
    { 

    } 
} 

答えて

2

私はちょうどここに推測しているが、私はあなたのプログラムの中で見る二つの問題があります:最初は、あなたが別の関数内ネストされた機能、すなわち機能を使用しようとしていることです。これはC++標準では許可されていませんが、一部のコンパイラでは言語の拡張機能として許可される場合があります。

第二の問題は、あなたが実際にあなただけ宣言、main関数内でそれらを関数を定義していないということです。あなたは

int input(); 
{ 
} 

を行うと、あなたが最初input関数プロトタイプの宣言を持っている、あなたは、ネストされたが、空のスコープを持っています。この問題は、ソースが実際にリンカーエラーでビルドに失敗することにつながるはずです。

第3の問題もあります。関数プロトタイプを、関数を呼び出す前にに宣言する必要があります。

あなたのプログラムの修正版は、次のようになります。あなたがそれらを使用する前に、関数を宣言する必要があり

#include <iostream> 
#include <fstream> 
#include <string> 
using namespace std; 

// Declare function prototypes, so the compiler knows these functions exist 
void input(); 
void search(); 
void edit(); 
void displayall(); 

int main() 
{ 
    ... 
    // Now you can call the functions 
    input(); 
    ...  
} 

void input() // Note: No semicolon here 
{ 
    ... 
} 

void search() // Note: No semicolon here 
{ 
    ... 
} 

void edit() // Note: No semicolon here 
{ 
    ... 
} 

void displayall() // Note: No semicolon here 
{ 
    ... 
} 
+0

私の問題は、入力ケース、検索ケースなどのスイッチケースの選択です。23行目でエラーが発生しました。 – Netherland

+0

@Netherland 2番目と3番目の問題について、でる?あなたは私の修正された疑似コードを見ましたか?それはあなたとどのように違うのでしょうか? –

0

。具体的には、input()関数は、最初の使用の後に宣言され、定義されています(main())。

関連する問題