#include <stdio.h>
#include <conio.h>

/* 
This program defines a table of possidle rod diameters of a
certain material X, and the corresponding maximum load that 
each rod can bear. The user can enter a diameter value and
request a load value, or a load value to get a suitable diameter
value.
please do not remove this comment.
source: C for Engineering, http://c4engineering.hypermart.net 
*/

/* Table definition */
#define N 7	/*Number of entries in table*/
float diam[N]={10,12,15,18,20,22,25},
      load[N]={420,540,658,860,1050,1230,1400};

void find_diam(void);
void find_load(void);

void main(void)
{
	char ch;

	do{
	  clrscr();
	  printf("\nThis program fetches data from a maximum load versus\nrod diameter table.\nPlease select an option:\n");
	  printf("\n\t[1] Find the max load given a diameter.\n\t[2] Find a suitable diameter given a load.\n\t[3] Quit.\n");
	  printf("\nYour selection:");
	  ch=getch();
	  if(ch=='1')	find_diam();
	  if(ch=='2')	find_load();
	}while(ch!='3');
	return;
}

void find_diam(void)
{
	int i;
	float l;

	printf("\n\nEnter the load required in Kg:");
	scanf("%f",&l);
	for(i=0;i<N;i++)
	{
	  if(l<=load[i])
	  {
		printf("\nSuitable diameter is %.1f mm",diam[i]);
		i=0;
		break;
	  }
	}
	if(i)	printf("\nLoad is too high.");
	printf("\n\nPress any key to return to menu...");
	getch();
	return;
}

void find_load(void)
{
	int i;
	float d;

	printf("\n\nEnter the rod diameter in mm:");
	scanf("%f",&d);
	for(i=0;i<N;i++)
	{
	  if(d<=diam[i])
	  {
		printf("\nStandard diameter is %.1f\nMaximum allowable load is %.1f Kg.",diam[i],load[i]);
		i=0;
		break;
	  }
	}
	if(i)	printf("\nMaximum available diameter is %.1f",diam[N]);
	printf("\n\nPress any key to return to menu...");
	getch();
	return;
}



