What wrong with my coding?
when i run..nothing appear..

The output should be:

Perimeter of Rectangle 1: 22
Perimeter of Rectangle 2: 6
Perimeter of Rectangle 3: 18
Perimeter of Rectangle 4: 4

#include<iostream>
using namespace std;

const int TOTAL= 4;
void CalculatePerimeter(int perimeter[], int width[], int height[]);
//const int i,j;
int main(){

int perimeter[TOTAL];
int width[TOTAL] = {6, 2, 6, 1};
int height[TOTAL] = {5, 1, 3, 1};
//int adding[TOTAL];


void CalculatePerimeter(int perimeter[], int width[], int height[]);

return 0;
}


void CalculatePerimeter(int perimeter[], int width[], int height[]){
for(int i=0;i<4;i++){
perimeter[i]=width[i]+height[i];
}

for(int j=0;j<4;j++){
perimeter[j]=perimeter[j]*2;
}

cout<<"Perimeter of Rectangle 1 : "<<perimeter[0]<<endl;
cout<<"Perimeter of Rectangle 2 : "<<perimeter[1]<<endl;
cout<<"Perimeter of Rectangle 3 : "<<perimeter[2]<<endl;
cout<<"Perimeter of Rectangle 4 : "<<perimeter[3]<<endl;
}

Now it works, when you call the function, please do not include and "int" and "double", etc.

#include<iostream>
using namespace std;

const int TOTAL= 4;
void CalculatePerimeter(int *, int *, int *);
//const int i,j;
int perimeter[TOTAL];
int width[TOTAL] = {6, 2, 6, 1};
int height[TOTAL] = {5, 1, 3, 1};

int main(){


CalculatePerimeter(perimeter, width, height);

return 0;
}


void CalculatePerimeter(int perimeter[], int width[], int height[]){
for(int i=0;i<4;i++)
{
    perimeter[i]=width[i]+height[i];
}

for(int j=0;j<4;j++)
{
    perimeter[j]=perimeter[j]*2;
}

cout<<"Perimeter of Rectangle 1 : "<<perimeter[0]<<endl;
cout<<"Perimeter of Rectangle 2 : "<<perimeter[1]<<endl;
cout<<"Perimeter of Rectangle 3 : "<<perimeter[2]<<endl;
cout<<"Perimeter of Rectangle 4 : "<<perimeter[3]<<endl;
}

The output are:

Perimeter of Rectangle 1 : 22
Perimeter of Rectangle 2 : 6
Perimeter of Rectangle 3 : 18
Perimeter of Rectangle 4 : 4

Process returned 0 (0x0)   execution time : 0.010 s
Press any key to continue.

line# 15:
This is not the way you invoke a function.
You should first know how to do that. Please read more about functions.


Some more feedbacks:

line# 22 and 26:
How do you handle the loop if the number of rectangle is variable. Better have another argument in the function which gives the number of rectangles.

line# 30 through 33:
Why are you repeating the same statements 4 times. You could have used a "for" loop here as you did before.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.