linker error

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.

//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;


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

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;
}
Last edited on
What are the errors?
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.

//shapes program

#include <iostream>
#include <iomanip>
// prototypes
int menu();
void square(int Sidef,char Symbolf);
void rectangle(int SideAf,int SideBf,char Symbolf);
void triangle(int Sidef,char Symbolf);
void rttriangle(int Basef,char Symbolf);
void diamond(int Heightf,char Symbolf);

using namespace std;

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 << "Enter the number of your shape selection:"<< endl << endl;
cout << "(1) Square\n";
cout << "(2) Rectangle\n";
cout << "(3) Right Triangle\n";
cout << "(4) Triangle\n";
cout << "(5) Diamond\n";
cout << "(6) Exit Program\n";
cin >> choice;
return choice;
}
//function definitions
void square(int Sidef,char Symbolf)
{
//local identifiers

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++)
{
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.)

Execution terminated
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

Here the same
for (int j=0; j<int width;j++)

The use of a for-loop is like
1
2
3
4
5
int max = 1234;
for (int i=0; i<max; i++)
{
  ...
}

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.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//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;
         }
Last edited on
closed account (z05DSL3A)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void square(int Sidef,char Symbolf)
{
    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 << Symbolf;
        }
        cout << endl;
    }
    return;
}
Last edited on
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//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;
        }
Topic archived. No new replies allowed.