- Jul 6, 2001
- 2,740
- 0
- 0
Ok heres what i get when i try to compile my program.
irix[1]% gcc -ansi -Wall test.c -lm
test.c: In function 'main':
test.c:56: parse error before 'double'
test.c:73: parse error before 'void'
test.c: in function 'DrawRect':
test.c:132: parse error at the end of imput.
Heres the code, The faces indicat line 56,73, and 132 respectively.
#include <stdio.h>
#include <math.h>
int Area( int width, int height );
int Perimeter( int width, int height );
double diagonal( int width, int height );
void DrawRect( int width, int height, char diplay );
void PrintMenu( void );
int main()
{
float diagonal;
int width, height, perimeter, area;
char display, response;
printf( "Enter a width: " );
scanf( "%d",&width );
while ( width < 1 )
{
printf( "Please enter a positive integer." );
scanf( "%d",&width );
}
printf( "Enter a height: " );
scanf( "%d",& height );
while ( height < 1 )
{
printf( "Please enter a positive whole number." );
scanf( "%d",&height );
}
getchar();
printf( "Enter a character to be used to draw the rectangle: " );
display = getchar();
do
{
getchar();
PrintMenu();
response = getchar();
switch(response)
{
case 'A': area = Area( width, height);
printf("The area is %d\n",area);
break;
case 'P': perimeter = Perimeter( width, height);
printf("The perimeter is %d\n",perimeter);
break;
case 'D': diagonal = double diagonal( width, height);
printf("The diagonal is %f\n",diagonal);
break;
case 'R': DrawRect( width, height, display );
break;
case 'Q': printf(" Closing Program.\n ");
break;
default: printf(" Not a valid menu option. ");
}while( response != 'Q' );
return 0;
}
void PrintMenu(void)
{
printf( " Menu \n" );
printf( "A - Calculate area of the rectangle.\n" );
printf( "P - Calculate the perimeter of the rectangle.\n" );
printf( "D - Calculate diagonal of the rectangle.\n" );
printf( "R - Display the rectagle.\n" );
printf( "Q - Quit.\n" );
printf( "Selection: ");
}
int Perimeter( int width, int height)
{
int perimeter;
perimeter = ((2 * width) + (2 * height));
return perimeter;
}
int Area( int width, int height)
{
int area;
area = (width * height);
return area;
}
double diagonal(int width, int height)
{
float diagonal;
diagonal = sqrt((width * width) + (height * height));
return diagonal;
}
void DrawRect( int width, int height, char display )
{
int heightcounter, widthcounter;
heightcounter = 1;
while( heightcounter <= height )
{
widthcounter = 1;
while( widthcounter <= width )
{
printf(" %c%c",display);
widthcounter = widthcounter + 1;
}
printf("\n");
heightcounter = heightcounter + 1;
return;
}
irix[1]% gcc -ansi -Wall test.c -lm
test.c: In function 'main':
test.c:56: parse error before 'double'
test.c:73: parse error before 'void'
test.c: in function 'DrawRect':
test.c:132: parse error at the end of imput.
Heres the code, The faces indicat line 56,73, and 132 respectively.
#include <stdio.h>
#include <math.h>
int Area( int width, int height );
int Perimeter( int width, int height );
double diagonal( int width, int height );
void DrawRect( int width, int height, char diplay );
void PrintMenu( void );
int main()
{
float diagonal;
int width, height, perimeter, area;
char display, response;
printf( "Enter a width: " );
scanf( "%d",&width );
while ( width < 1 )
{
printf( "Please enter a positive integer." );
scanf( "%d",&width );
}
printf( "Enter a height: " );
scanf( "%d",& height );
while ( height < 1 )
{
printf( "Please enter a positive whole number." );
scanf( "%d",&height );
}
getchar();
printf( "Enter a character to be used to draw the rectangle: " );
display = getchar();
do
{
getchar();
PrintMenu();
response = getchar();
switch(response)
{
case 'A': area = Area( width, height);
printf("The area is %d\n",area);
break;
case 'P': perimeter = Perimeter( width, height);
printf("The perimeter is %d\n",perimeter);
break;
case 'D': diagonal = double diagonal( width, height);
printf("The diagonal is %f\n",diagonal);
break;
case 'R': DrawRect( width, height, display );
break;
case 'Q': printf(" Closing Program.\n ");
break;
default: printf(" Not a valid menu option. ");
}while( response != 'Q' );
return 0;
}
void PrintMenu(void)
{
printf( " Menu \n" );
printf( "A - Calculate area of the rectangle.\n" );
printf( "P - Calculate the perimeter of the rectangle.\n" );
printf( "D - Calculate diagonal of the rectangle.\n" );
printf( "R - Display the rectagle.\n" );
printf( "Q - Quit.\n" );
printf( "Selection: ");
}
int Perimeter( int width, int height)
{
int perimeter;
perimeter = ((2 * width) + (2 * height));
return perimeter;
}
int Area( int width, int height)
{
int area;
area = (width * height);
return area;
}
double diagonal(int width, int height)
{
float diagonal;
diagonal = sqrt((width * width) + (height * height));
return diagonal;
}
void DrawRect( int width, int height, char display )
{
int heightcounter, widthcounter;
heightcounter = 1;
while( heightcounter <= height )
{
widthcounter = 1;
while( widthcounter <= width )
{
printf(" %c%c",display);
widthcounter = widthcounter + 1;
}
printf("\n");
heightcounter = heightcounter + 1;
return;
}