0

このプログラムは関数を教えることになっています。関数をそれぞれヘッダーファイルに分けました。後方または欠落している中括弧がどこかにあると思いますが、私はこのプログラムを何時間も見つめ、物事を再配置しようとしましたが、何もうまくいかないようです.

このプログラムは、電話番号を読み取り、それを出力することになっています。文字が指定されている場合は、大文字にした後、電話のキーパッドのように 0 ~ 9 の数字に並べ替えます。また、無効な文字などのエラー コードも返します。これは、switch ステートメントによって制御されます。

主な機能

私が得ているエラーの 1 つは、最後の行の右中括弧にあります。

入力の最後に '}' が必要です

#include <iostream>
#include <cctype>
#include "Read_Dials.h"
#include "To_Digit.h"
#include "Acknowledge_Call.h"

using namespace std;


int main()
{
    char digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8;
    int return_value = 0;

    return_value = int Read_dials(digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8);

    if (return_value != -5)
        break;

        switch(return_value){

            case -1:
            cout << "ERROR - An invalid character was entered. Please try again, only numbers or letters this time." << endl;
                break;
        case -2:
            cout << "ERROR - Phone number cant start with 0." << endl;
                break;
        case -3:
            cout << "ERROR - This isn't the movies, Phone numbers dont start with \" 555 \" here buddy :/" << endl;
                break;
        case -4:
            cout << "ERROR - Please make sure the hyphen is in position 4." << endl;
                break;
            default:
                void Acknowledge_Call(digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8);
        }
return 0;
}

Read_Dials 関数

この関数にエラーはありません

int Read_Dials(char &num1, char &num2, char &num3, char &num4, char &num5, char &num6, char &num7, char &num8)
{

#include "To_Digit.h"

int i = 0;

    do{
    i++;
    cout << "Please enter the character for position #" << i << " in the phone number\n";
    cout << "NOTE: Please put the hyphen \" - \" in the fourth position and use \"Q\"to quit." << endl;
    char temp;
    cin >>temp;

        if (i = 1 && temp == 0)
        {
            return_value = -2;
        }
        else if (i == 1 && (temp == 'q' || temp == 'Q'))
        {
            return_value -5;
        }

        else if (i == 1)
        {
            temp = &num1;
            &inputValue = &num1;
            int To_Digit(char &num1);       
        }
        else if (i == 2)
        {
            temp = &num2;
            &inputValue = &num2;
            int To_Digit(char &num2);
        }
        else if (i == 3)
        {
            temp = &num3;
            &inputValue = &num3;
            int To_Digit(char &num3);
        }
        else if (&num1 == '5' && &num2 == '5' && &num3 == '5')
        {
            return_value -3;
        }
        else if (i == 4 && temp != '-')
        {
            return_value -4;
        }
        else if (i == 5)
        {
            temp = &num5;
            &inputValue = &num5;
            int To_Digit(char &num5);
        }
        else if (i == 6)
        {
            temp = &num6;
            &inputValue = &num6;
            int To_Digit(char &num6);
        }
        else if (i == 7)
        {
            temp = &num7;
            &inputValue = &num7;
            int To_Digit(char &num7);
        }
        else if (i == 8)
        {
            temp = &num8;
            &inputValue = &num8;
            int To_Digit(char &num8);
        }
    }while (i < 8)
    return 0;
}

To_Digit 関数

私が得ている2番目で最後のエラーは、2行目(左中括弧)にあります:

関数定義は、'{' トークンの前では許可されていません

int To_Digit(char &inputValue)
{

char &inputValue;

    if (isdigit(&inputValue))
        break;

    &inputValue = toupper(&inputValue);

    switch(&inputValue){

        case 'A': case 'B': case 'C':
            &inputValue = '2'; 
                break;

        case 'D': case 'E': case 'F':
            &inputValue = '3'; 
                break;

        case 'G': case 'H': case 'I':
            &inputValue = '4'; 
                break;

        case 'J': case 'K': case 'L':
            &inputValue = '5'; 
                break;

        case 'M': case 'N': case 'O':
            &inputValue = '6'; 
                break;

        case 'P': case 'Q': case 'R': case 'S':
            &inputValue = '7'; 
                break;

        case 'T': case 'U': case 'V':
            &inputValue = '8'; 
                break;

        case 'W': case 'X': case 'Y': case 'Z':
            &inputValue = '9'; 
                break;
        default:
            return -1;

    }
}

Acknowledge_Call 関数

この関数でエラーはありません。

void Acknowledge_Call(digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8)
{
    cout << "Phone number entered is: " << digit1 << digit2 << digit3 << digit4 << digit5 << digit6 << digit7 << digit8 << endl;
}

このコードの何が問題になっていますか? どうすれば修正できますか?

4

4 に答える 4

2
 default:
     void Acknowledge_Call(digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8);

関数の呼び出し中は、戻り型は使用されません。だから、ドロップしvoidます。また、defaultケースにはbreak、が必要です。そうでない場合は、フォールスルーします。


int Read_Dials(char &num1, char &num2, char &num3, char &num4, char &num5, char &num6, char &num7, char &num8)
{

   #include "To_Digit.h"  // The header actually has a definition. Preprocessor 
                          // copies the content of To_Digit.h here. So, you have
                          // a function definition inside another function while 
                          // compilation phase which is not allowed. So remove
                          // it and place it at top of the file.
   // .....

}
于 2011-03-24T19:13:20.003 に答える
2

私はまだ自分でコードを実行しようとはしていませんが、私にとってはおかしなことに見える唯一のことは、「Read_Dials」関数にあります...関数内に#INCLUDEステートメントを入れないでください。これらのステートメントは常にファイルの先頭に配置してください。

#includeを移動して、その機能をお知らせください。幸運を。

于 2011-03-24T19:17:14.883 に答える
2

#includes はファイルの先頭にある必要があります...

if (return_value != -5)
    break;

(メインで) は、抜け出すためのループがないため許可されていません

于 2011-03-24T19:27:08.780 に答える
0

ここにいくつかの問題があります(ヘッダーファイルを提供しなかったという事実に加えて):

  1. "default" の後の関数宣言関数呼び出しの前を main()
    削除します。void

  2. Acknowledge_Call
    変更の宣言で指定されていないパラメーターの型:
    void Acknowledge_Call(char digit1, char digit2, char digit3, char digit4, char digit5, char digit6, char digit7, char digit8)

  3. 関数内のintin before を削除します。 Read_dialsmain

  4. main()、「Read_dials toRead_Dials != != 」を変更します。:
    The C++ language is case-sensitive, thus 'dials
    DialsdIaLs

  5. 関数内breakの after から削除: またはまたはifmain()
    return 1;return EXIT_FAILURE;exit(1);

  6. これらの行を に追加することを忘れないでくださいAcknowledge_Calls.cpp:

    #include "acknowledge_call.h"
    #include <iostream>
    using namespace std;

  7. これらの行を に追加することを忘れないでくださいRead_Dials.cpp:

    #include "read_dials.h"
    #include <iostream>
    using namespace std;

  8. で、 をファイルの先頭に Read_Dials.cpp移動します。#include "To_Digit.h

  9. 関数をすべて実行するときは、戻り値の型もパラメーターの型も呼び出しに含めないでください。
    たとえば、次を使用します
    num1 = To_Digit(digit1);

    int To_Digit(char &num1);

関数を呼び出してパラメーターを渡す方法について、インストラクターと長い間話し合う必要があります (今回は、注意深く聞いてください)。また、C++ に関する優れた本を読んでください。

于 2011-03-24T20:03:59.957 に答える