#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <math.h>
#include <time.h>
void clrscr(void);
void sleep (clock_t);
void main(void)
{
//Declare
char speed;
float radius;
float length;
float flow_rate;
time_t t;
//Initialize
radius = 0;
length = 0;
speed = 0;
flow_rate = 0;
printf("\n\tProcess Control System.\n");
printf("\n\tThis Program will monitor the speed of a pump motor and a flow sensor.\n");
printf("\n\tThe user will enter the parameters of the system and start\n");
printf("\tthe system. The user can enter different values of speed by\n");
printf("\tpressing any key. The escape key will stop the system.\n");
repeat:
printf("\n\n\tPlease enter the rotor radius in cm => ");
scanf("%f",&radius);
printf("\n\n\tPlease enter the shaft length in cm => ");
scanf("%f",&length);
if(radius <= length)
{
printf("\n\n\tPlease enter the maximum speed => ");
scanf("%c",&speed);
flow_rate = sqrt(speed*tan(radius/ length));
time(&t);
printf("\n\tspeed<m/s>\tflow rate <1/s>\tCurrent time\n\n");
printf("\t%c\t%f\t%s\n",speed,flow_rate,ctime(&t));
goto repeat;
}
else
{
clrscr();
printf("\n\tTry again.\n\n");
goto repeat;
}
}
void clrscr(void)
{
HANDLE hndl = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hndl, &csbi);
DWORD written;
DWORD N = csbi.dwSize.X * csbi.dwCursorPosition.Y + csbi.dwCursorPosition.X + 1;
COORD curhome = {0,0};
FillConsoleOutputCharacter(hndl, ' ', N, curhome, &written);
csbi.srWindow.Bottom -= csbi.srWindow.Top;
csbi.srWindow.Top = 0;
SetConsoleWindowInfo(hndl, TRUE, &csbi.srWindow);
SetConsoleCursorPosition(hndl, curhome);
}
void sleep(clock_t delay)
{
clock_t stoptime;
stoptime = delay + clock();
while( stoptime > clock() ){ ; }
}