PDA

View Full Version : **** functions always error


mugen
06-20-04, 07:01 PM
can any knowledgeble ppl help me out with my code? i cant find the problems to the functions ;/


// JC Lopez June 16, 2004
// Write a program that calculates the area and the perimeter of rectangle.

#include<stdio.h>

//-----Function Prototype------>
void printHeading (void);
int getWidth(int width);
int getLength();
void calculateArea();
void calculatePerimeter(void);
int printArea(void);
int printPerimeter(void);
//----------------------------->

//----Globals---->
int width, length;
int area, perimeter;


int main (void)
{
int width, length;

printHeading();

getWidth();
getLength();

calculateArea();
calculatePerimeter();

printArea();
printPerimeter();

return (0);
}

// printHeading
void printHeading(void)
{
printf("JC Lopez\n");
printf("June 16, 2004\n");
printf("Assignment #1\n");
}

// getWidth
int getWidth()
{
printf("Please enter the width/n");
scanf("%d", &width);
}

// getLength
void getlength()
{
printf("Please enter the length\n");
scanf("%d", &length);
}

// calculateArea
void calculateArea(void)
{
return area = length * width;

}

// calculatePerimeter
void calculatePerimeter(int perimeter)
{
return perimeter = 2 * (length * width);

}

//printArea
int printArea(void)
{
printf("The area of a rectangle of width %d and length %d is %d\n", width, length, printArea())
}

//printPerimeter
int printPerimeter(void)
{
printf("The perimeter of a rectangle of width %d and length %d is %d\n", width, length, printPerimeter())
}

Extus
06-22-04, 12:05 PM
a)To the function int getwidth
you forgot to declare a value inside th parenthesess : int getwidth(int ...)

b)The functions that you declared as void can not return a value!

kash
06-22-04, 08:38 PM
// JC Lopez June 16, 2004
// Write a program that calculates the area and the perimeter of rectangle.

#include<stdio.h>

//-----Function Prototype------>
void printHeading (void);
void getWidth(int width);
void getLength();
void calculateArea();
void calculatePerimeter(void);
void printArea(void);
void printPerimeter(void);
//----------------------------->

//----Globals---->
int width, length;
int area, perimeter;


int main (void)
{
int width, length;

printHeading();

getWidth();
getLength();

calculateArea();
calculatePerimeter();

printArea();
printPerimeter();

return (0);
}

// printHeading
void printHeading(void)
{
printf("JC Lopez\n");
printf("June 16, 2004\n");
printf("Assignment #1\n");
}

// getWidth
void getWidth()
{
printf("Please enter the width/n");
scanf("%d", &width);
}

// getLength
void getlength()
{
printf("Please enter the length\n");
scanf("%d", &length);
}

// calculateArea
void calculateArea(void)
{
area = length * width;

}

// calculatePerimeter
void calculatePerimeter(int perimeter)
{
perimeter = 2 * (length * width);

}

//printArea
void printArea(void)
{
printf("The area of a rectangle of width %d and length %d is %d\n", width, length, area)
}

//printPerimeter
void printPerimeter(void)
{
printf("The perimeter of a rectangle of width %d and length %d is %d\n", width, length, perimeter )
}

mugen
06-27-04, 05:57 PM
Thank you for your help guys, ive done the changes to the code all i have to do i complie it tomorrow :D they require me to complie only to borland and i dont have the bloodshed dev c++

anyways thanks again for the help :)