Reputation: 11
So I honestly have no idea what's wrong with my code. Any suggestions would help. Look at the section of the code where I comment(towards the middle). the computer gives me an error saying expected a";". Something is wrong with the bracket or i screwed up some where else and just can't find it.
//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();
}
}
}
Upvotes: 0
Views: 190
Reputation: 206498
You cannot define a function within another function. You defined a function checkd()
inside the main
function.
Move the function body outside the main
and just call the function from main
as:
checkd(d);
Probably, You also want the function to take an parameter which it needs to compare.
Also,
void a();
does not call the function a()
it just declares the function, to call the function you need:
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;
}
Upvotes: 1