0

したがって、正直なところ、自分のコードの何が問題なのかわかりません。どんな提案も役に立ちます。私がコメントしているコードのセクションを見てください(中央に向かって)。コンピューターは、「;」が必要であるというエラーを表示します。ブラケットに何か問題があるか、他の場所を台無しにして、それを見つけることができません。

//Experiment2
//Creating functions and recalling them.
#include <iostream>
using namespace std;

void a()
{
cout<<"You try running but trip and fall and the crazy man kills you!!!!                     HAAHAHAHHAHA.";
}


void b()
{
cout<<"You stop drop and roll and the crazy man is confused by this and leaves you alone!";
}

void c()
{
cout<<"you try fighting the man but end up losing sorry!";
}




int main()
{
int a;
int b;
int c;
int d;
a=1;
b=2;
c=3;

cout<< "Once upon a time you was walking to school,\n";
cout<< " when all of the sudden some crazy guy comes running at you!!!!"<<endl;
cout<< " (This is the begining of your interactive story)"<<endl;
cout<< "Enter in the number according to what you want to do.\n";
cout<< " 1: run away, 2:stop drop and roll, or 3: fight the man."<<endl;
cin>>d;
void checkd()
//i dont know whats wrong with the bracket! the computer gives me an error saying expected a";"
{
    if(d==1)

    {
        void a();
    }

    if(d==2)

    {
        void b();
    }

    if(d==3)

    {
        void c();
    }
}
}
4

1 に答える 1

1

別の関数内で関数を定義することはできません。checkd()関数内で関数を定義しましたmain

関数本体をの外に移動し、次のmainように関数を呼び出しますmain

checkd(d);

おそらく、関数が比較す​​る必要のあるパラメーターを受け取ることも必要です。

また、

void a();

関数を呼び出さずa()、必要な関数を呼び出すために、関数を宣言するだけです。

a();

void checkd(int d)

{
    if(d==1)

    {
        a();
    }

    if(d==2)

    {
        b();
    }

    if(d==3)
    {
        c();
    }
}
int main()
{
    ....
    ....
    cout<< " 1: run away, 2:stop drop and roll, or 3: fight the man."<<endl;
    cin>>d;
    checkd();

    return 0;
}
于 2013-01-04T09:10:36.260 に答える