Problems with compilation

Jun 12, 2013 at 7:55am
Hey everyone,

I am having some issues with a class assignment I am working on. It would be great if anyone could tell me why this is not running. It keeps telling me that the length/width/radius on lines 26/29/32 respectively are missing identifiers. Also on lines 25/28/31, it says "syntax error : missing ';' before 'type'". I am new to all this and it is my first semester, so I am very much still prone to making plentiful mistakes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>

int GetNum(void)
{
	int number44;
	scanf("%d", &number44);
	return number44;
}

int CalcAreaR(int length, int width)
{
	int AreaR = length * width;
	return AreaR;
}

double CalcAreaC(int radius)
{
	double AreaC = 3.14 * radius * radius;
	return AreaC;
}

int main()
{
	printf("Enter length: ");
	int length = GetNum();
	scanf("%d", &length);
	printf("Enter width: ");
	int width = GetNum();
	scanf("%d", &width);
	printf("Enter radius: ");
	int radius = GetNum();
	scanf("%d", &radius);
	
	printf("The area of the rectangle is %d.", CalcAreaR);
	printf("The area of the circle is %f.", CalcAreaC);

	return 0;
}


Thanks again everyone.
Jun 12, 2013 at 8:00am
i'm not sure about the syntax error but just out of curiosity, why are you again reading the variables after reading them through the function?

EDIT: while calling the CalcArea functions you need to provide them input parameters
Last edited on Jun 12, 2013 at 8:03am
Jun 12, 2013 at 8:08am
I just realized that was the problem with lines 26/29/32. And could you please give me an example of those parameters?
Jun 12, 2013 at 9:13am
1
2
printf("The area of the rectangle is %d.", CalcAreaR( length, width ) );
printf("The area of the circle is %f.", CalcAreaC( radius ) );
Jun 12, 2013 at 9:28am
You are calling scanf twice effectively.
Jun 12, 2013 at 4:32pm
GetNum is effectively scanf, and you are calling it, and scanf!
Also you never supplied parameters to the GetArea functions (AreaR, AreaC)!

Fixed Main (untested):


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main() {

	printf("Please enter the length of the rectangle: ");
	int Length = GetNum();

	printf("Please enter the width of the rectangle: ");
	int Width = GetNum();

	printf("Please enter the radius of the circle: ");
	int Radius = GetNum();

	printf("The area of the rectangle is %d.\n", CalcAreaR(Length, Width));
	printf("The area of the circle is %f.\n", CalcuAreaC(Radius));

	return 0;

}
Topic archived. No new replies allowed.