Ok so i got this code working but then i realized that my teacher is a lame and wont accept it bc its dooesnt use Multiple Functions with Input/Output Parameters and i have no idea how to do that :/ i wondering if you could give me a example or idk :/
heres the problem question Write a menu program that will print various formulas and do calculations. For each menu choice, display the formula and prompt for the necessary values. Then calculate and print the area and the perimeter.
Your program must have 5 functions as follow:
1) int getMenuChoice( ); // display the menu, get and return the choice.
2) void Circle( double *radius, double *area, double *perimeter ); // display the formulas, get the radius, calculate the area and the perimeter, function should return the values through the output perimeters.
3) void displayCircle( double radius, double area, double perimeter ); // display the all the values in a tabular format.
4) void Rectangle( double *length, double *width, double *area, double *perimeter ); // display the formulas, get the length and the width, calculate the area and the perimeter, function should return the values through the output perimeters.
5) void displayRectangle( double length, double width, double area, double perimeter ); // display the all the values in a tabular format.
Code:
#include <stdio.h>
/*void DisplayMenu (void) ;
int GetMenuChoice (void) ;
void Circle( double *radius, double *area, double *perimeter );
void displayCircle( double radius, double area, double perimeter );
void Rectangle( double *length, double *width, double *area, double *perimeter );
void displayRectangle( double length, double width, double area, double perimeter */
/*void DisplayMenu (void) ;*/
int GetMenuChoice (void) ;
int main(void)
{
char choice;
do
{
printf("\n-------------Menu of Shapes---------------");
printf("\n\'A\'Circle\n\'B\'Rectangle\n\'C\'Quit :");
fflush(stdin);
scanf("%c", &choice);
/*int GetMenuChoice (void) ; */
switch(choice)
{
case 'A':
case 'a':
/*void Circle( double *radius, double *area, double *perimeter ); */
{
printf("----------Proccessing Circle-----------\n\n");
printf("Area of Circle = 3.14 * Radius * Radius\n");
printf("Perimeter of Circle = 2 * 3.14 * Radius\n\n");
float radius;
printf("Enter the radius :");
scanf("%f", &radius);
/*void displayCircle( double radius, double area, double perimeter );*/
printf("----------------Results----------------\n\n");
printf("Radius is %.1f",radius);
printf("\nArea of circle is %.1f", 3.14 * radius * radius);
printf("\nPerimeter of circle is %.1f", 2 * 3.14 * radius);
printf("\n\n------------------------------------------");
break;
}
case 'B':
case 'b':
/*void Rectangle( double *length, double *width, double *area, double *perimeter ); */
{
printf("----------Proccessing Rectangle-----------\n\n");
printf("Area of Rectangle = Length * Width\n");
printf("Perimeter of Rectangle = 2*Length + 2*Width \n\n");
float length, width;
printf("Enter the Length :");
scanf("%f", &length);
printf("Enter Width :");
scanf("%f", &width);
/*void displayRectangle( double length, double width, double area, double perimeter */
printf("----------------Results----------------\n\n");
printf("\nWidth is %.1f",width);
printf("\nLength is %.1f",length);
printf("\nArea of rectangle is %.1f", length * width);
printf("\nPerimeter of rectangle is %.1f", 2 * (length + width));
printf("\n\n------------------------------------------");
break;
}
default :
printf("\nInvalid choice");
}
}while(choice != 'c' && choice != 'C');
return 0;
}