Assignment

Write a C Program that ask the user what they would like to calculate, input their choice call the correct input function, calculate the answer, output the answer and repeat until they choose to quit

// Title:
// Author: Heather Uthoff
// Description:
// - ask the user what they would like to calculate
// - input their choice
// - call the correct input function
// - calculate the answer
// - output the answer
// - repeat until they choose to quit

#include

main ()
{
  int selectv,temp;
   do
    selectv=selectf(temp);
  while(selectv != 4);
  return 0;
}

//ask the user what they would like to calculate
int selectf(float selectv)
{
 float temp;

  printf("Enter the code to make your selection:\n");
  printf("1 - Perimeter\n");
  printf("2 - Volume\n");
  printf("3 - Area\n");
  printf("4 - Quit\n");
  printf(": ");
  scanf("%f",&selectv);

  if(selectv == 1)
   getperimf(temp);
  if (selectv == 2)
   getvolf(temp);
  if (selectv == 3)
   getareaf(temp);

  return selectv;

}

//get the measurements and calculate perimeter
int getperimf()
{
  char choice;
  float length, width, perimv;


  printf("\nWhat is the length in inches?:");
  scanf("%f",&length);
  printf("\nWhat is the width in inches?:");
  scanf("%f",&width);
  printf("\nYou entered a length of %f and a width of %f.\n",length,width);
  printf("Is this correct?(y/n):");
  while(getchar() != '\n') continue;
  scanf ("%c",&choice);
  if(choice == 'y')
  {
   perimv=2*(length+width);
   printf("\n\nThe perimeter is %f\n\n",perimv);
   return 0;
  }
  else
  {
   while(choice != 'y')
   {
   getperimf();
   return 0;
   }
  }
}

//get the measurements and calculate volume
int getvolf()
{
  char choice;
  float length, width, height, volv;

  printf("\nWhat is the length in inches?:");
  scanf("%f",&length);
  printf("\nWhat is the width in inches?:");
  scanf("%f",&width);
  printf("\nWhat is the height in inches?:");
  scanf("%f",&height);

  printf("\nYou entered a lgth of %f, a wdth of %f, and a hght of %f\n\n",length,width,height);
  printf("Is this correct?(y/n):");
  while(getchar() != '\n') continue;
  scanf ("%c",&choice);
  if(choice == 'y')
  {
   volv=length*width*height;
   printf("\n\nThe volume is %f\n\n",volv);
   return 0;
  }
  else
  {
   while(choice != 'y')
   {
   getvolf();
   return 0;
   }
  }


//get the measurements and calculate area
int getareaf()
{
  char choice;
  float length, width, areav;

  printf("\nWhat is the length in inches?:");
  scanf("%f",&length);
  printf("\nWhat is the width in inches?:");
  scanf("%f",&width);

  printf("\nYou entered a length of %f, and a width of %f\n\n",length,width);
  printf("Is this correct?(y/n):");
   while(getchar() != '\n') continue;
  scanf ("%c",&choice);
  if(choice == 'y')
  {
  areav=length*width;
  printf("\n\nThe area is %f\n\n",areav);
  return 0;
  }
  else
  {
   while(choice != 'y')
   {
   getareaf();
   return 0;
   }
  }
}