with the following program instaled on an old machine with a pc based control running DOS, i am trying to get some data out of these functions. dont worry about the numbers you enter. the problem is that after it runs one of the functions and asks for a new choice, i have to enter the choice twice in order for it to be picked up. or press ENTER and then the choice. sort of like my grand father that never hears the first time
thnx in advance..
// Milling
#include <stdio.h>
#define PI 3.14
char get_choice(void);
char get_first(void);
float sfm(void);
float rpm(void);
float ipm(void);
float fpt(void);
//float hp(float DepthOfCut, float WidthOfCut, float feed, float MachinabilityConstant);
int main(void)
{
int choice;
while ((choice = get_choice()) != 'q')
{
switch (choice)
{
case 'a' : sfm();
break;
case 'b' : rpm();
break;
case 'c' : ipm();
break;
case 'd' : fpt();
break;
// case 'e' : hp();
// break;
default : printf("Program error!\n");
break;
}
}
printf("Bye.\n");
return 0;
}
char get_choice(void) // menu function
{
int ch;
printf("a: SFM having cutter Dia and RPM.\n");
printf("b: RPM having SFM and cutter Dia.\n");
printf("c: IPM having Feed per Tooth, Number of Teeth and RPM.\n");
printf("d: FPT having IPM Number of Teeth and RPM.\n");
//printf("e: HP having Depth of Cut, Width of Cut and feed.\n\n");
printf("ENTER CHOICE: ");
ch = get_first();
while ((ch < 'a' || ch > 'e') && ch != 'q')
{
printf("choose from the above numbers or Q to quit.");
ch = get_first();
}
return ch;
}
char get_first(void)
{
int ch;
ch = getchar();
while (getchar() != '\n')
continue;
return ch;
}
float sfm(void)
{
float doc_; // depth of cut
float rpm_; // rpm
float sfm_; // surface feet per minute
printf("Enter Diameter of Cutter ");
scanf("%f", &doc_);
printf("Enter RPM: ");
scanf("%f", &rpm_);
sfm_ = (PI * doc_ * rpm_) / 12;
printf("SFM is equal to %.2f.\n\n\n",sfm_);
return 0;
}
float rpm(void)
{
float sfm_; // surface feet per minute
float cd_; // cutter diameter
float rpm_; // rpm
printf("Enter SFM: ");
scanf("%f", &sfm_);
printf("Enter Cutter Diameter: ");
scanf("%f", &cd_);
rpm_ = (sfm_ * 12) / (PI * cd_);
printf("RPM is equal to %.2f.\n\n\n",rpm_);
return 0;
}
float ipm(void)
{
float fpt_; // feed per tooth
float not_; // number of teeth
float rpm_; // rpm
float ipm_; // inches per minute
printf("Enter Feed per Tooth: ");
scanf("%f", &fpt_);
printf("Enter Number of Teeth: ");
scanf("%f", ¬_);
printf("Enter RPM: ");
scanf("%f", &rpm_);
ipm_ = (fpt_ * not_ * rpm_);
printf("IPM is equal to %.2f.\n\n\n",ipm_);
return 0;
}
float fpt(void)
{
float ipm_; // inches per minute
float not_; // number of teeth
float rpm_; // rpm
float fpt_; // feed per tooth
printf("Enter ipm: ");
scanf("%f", &ipm_);
printf("Enter Number of Teeth: ");
scanf("%f", ¬_);
printf("Enter RPM: ");
scanf("%f", &rpm_);
fpt_ = (ipm_) / (not_ * rpm_);
printf("FPT is equal to %.2f.\n\n\n",fpt_);
return 0;
}