Hello I have been working on this program for days and am hung up on my function definitions when trying to compile. Here is part of my program I am working on any advice or direction about where to begin to fix it would be much appreciated. There is a menu in it which I finished along with a switch which I think I completed right this is the section where I am having trouble.
cout<<"The length of side A is:<<sideAf<<and the lenght of sideB is:"<<SideBf<<endl;
cout<<"The design is made of:\t"<<Symbolf<<endl;
return;
}
for(int i=0, i<length;i++)
{for(int j=0, j<width;j++)
cout<<Symbol,
cout<<endl;
}//end of rectangle function
}
void triangle(int Sidef,char Symbolf)
{
//local identifiers
char Symbol,
int Side;
cout<<"The height of the triangle is:\t"<<Side<<endl;
cout<<"The design is made of:\t"<<Symbol<<endl;
return;
}
void rttriangle(int Basef,char Symbolf)
{
//local identifiers
int Base;
char Symbol;
cout<<"The height of the right triangle is:\t"<<Base<<endl;
cout<<"The design is made of:\t"<<Symbol<<endl;
return;
for( int i = 0; i <Base; i++ )
cout << Symbol;
}
Here is the whole program I have so far. I am concerned with the structure of it. I know my for loops to out put the shapes may not be working correctly yet as I wanted to see if I had the rest right so far. I will go back and get the errors and post them next.
int main()
{
//local identifiers
char Symbol;
int Base, Height, Side, SideA, SideB, Choice;
bool exit = false;
for (; ;)
{
int Choice = menu();
switch(Choice)
{
case (1 ):
cout<<"Please input the length of the square:\t";
cin>>Side;
cout<<"Please input symbol for design:\t";
cin>>Symbol;
square(Side,Symbol);
break;
case (2):
cout<<"Please input the length of side A of Rectangle:\t";
cin>>SideA;
cout<<"Pleas input the length of side B of Rectangle:\t";
cin>>SideB;
cout<<"Please input symbol for design:\t";
cin>>Symbol;
rectangle(SideA,SideB,Symbol);
break;
case (3):
cout<<"Pleas enter base of right triangle:\t";
cin>>Base;
cout<<"Please input symbol for design:\t";
cin>>Symbol;
rttriangle(Base,Symbol);
break;
case (4):
cout<<"Pleas enter height of triangle:\t";
cin>>Height;
cout<<"Please input symbol for design:\t";
cin>>Symbol;
triangle(Side,Symbol);
break;
case (5):
cout<<"Please enter height of diamond:\t";
cin>>Side;
cout<<"Please input symbol for design:\t";
cin>>Symbol;
diamond(Height,Symbol);
case (6):
exit=true;
break;
default:
cout << "Please select again invalid choice!" << endl;
break;
} // end switch
if (exit == true)
break;
}
return 0;
}
int menu()
{
int choice;
cout <<"The length of the side is:\t"<<Sidef<<endl;
cout<<"The design is made of:"<<Symbolf<<endl;
for (int i=0;int i<int length;i++)
{
for (int j=0; j<int width;j++)
cout<<Symbol;
cout<<endl;
//end of square function
return;
}
void rectangle(int SideAf,int SideBf,char Symbolf)
{
//local identifiers
cout<<"The length of side A is:<<sideAf<<and the lenght of sideB is:"<<SideBf<<endl;
cout<<"The design is made of:\t"<<Symbolf<<endl;
return;
}
for(int i=0; i<length;i++)
for(int j=0; j<width;j++)
cout<<Symbol;
cout<<endl;
}//end of rectangle function
void triangle(int Sidef,char Symbolf)
{
//local identifiers
char Symbol;
int Side;
cout<<"The height of the triangle is:\t"<<Side<<endl;
cout<<"The design is made of:\t"<<Symbol<<endl;
return;
}
void rttriangle(int Basef,char Symbolf)
{
//local identifiers
int Base;
char Symbol;
cout<<"The height of the right triangle is:\t"<<Base<<endl;
cout<<"The design is made of:\t"<<Symbol<<endl;
return;
for( int i = 0; i <Base; i++ )
cout << Symbol;
}
void diamond(int heightf,char symbolf)
{
//local identifiers
int Height;
char Symbol;
cout<<"The height of the diamond is:\t"<<Height<<endl;
cout<<"The design is made of:\t"<<Symbol<<endl;
return;
}
Here are the errors so far
In function `void square(int, char)':
103: error: expected primary-expression before "int"
:103: error: expected `;' before "int"
:103: error: expected primary-expression before "int"
:103: error: expected `)' before "int"
:103: error: expected primary-expression before "int"
:103: error: expected `;' before "int"
103: error: name lookup of `i' changed for new ISO `for' scoping
:103: error: using obsolete binding at `i'
:103: error: expected `;' before ')' token
:112: error: a function-definition is not allowed here before '{' token
:112: error: expected `,' or `;' before '{' token
:121: error: `length' undeclared (first use this function)
:121: error: (Each undeclared identifier is reported only once for each function it appears in.)
please write your code inside the source tags next time.
One error I can see is
1 2 3 4 5 6 7 8
int Symbol, Side, lenght, width;
cout <<"The length of the side is:\t"<<Sidef<<endl;
cout<<"The design is made of:"<<Symbolf<<endl;
for (int i=0;int i<int length;i++)
length is still defined so write it without int. Also you setted no value to langth before
Well I added your suggestion still having issues with it. In this program the user inputs the value of length and width and since the square has equal sides I put both the length and width equal to Sidef. I suppose if I can get this square function working I can model the rest of them like it. I am still getting errors not sure why.
//function definitions
void square(int Sidef,char Symbolf)
{
//local identifiers
int Symbol, Side;
cout <<"The length of the side is:\t"<<Sidef<<endl;
cout<<"The design is made of:"<<Symbolf<<endl;
int length = Sidef;
int width = Sidef;
for(int i=0; i<length;i++)
{
for (int j=0; j<width;j++)
{
cout<<Symbol;
cout<<endl;
return;
}
Please properly indent the code as well. The code tags aren't that helpful when the code is not neatly formatted. Take a look at this and you should see the problem very clearly. I have reposted your code more neatly. The error is obviously that you don't have enough closing brackets. This will cause all kinds of problems because the compiler starts compiling everything after this function definition incorrectly.