#include<iostream>  // JACK LEE /990212-01-5315/ A19EC023057 / SECTION 07 / 12.11.2019
#include<cmath> // MUHAMMAD SUHAIL / C0082352 / A19EC0269 / SECTION 07 / 12.11.2019
using namespace std;
int getProblem();
void getRateDropFactor (double&r, double&f);
void getKgRateConc (double&R,double&w,double&c);
int figDropsMin (double r, double f);
int byWeight (double R, double w, double c);


int getProblem()
{
	int n ;
	

	cout << endl ;
	cout << "Enter the number of the problem you wish to solve. " << endl ;
	cout << "     GIVEN A MEDICAL ORDER IN            CALCULATE RATE IN " << endl ;
	cout << "(1) ml/hr & tubing drop factor             drops/min " << endl ;
	cout << "(2) mg/kg/hr & concentration in mg/ml      ml/hr " << endl ;
	cout << "(3) QUIT" << endl ;
	cout << endl ;
	cout << "Problem => " ;
	cin >> n ;
	
	return n ;
}

void getRateDropFactor (double&r, double&f)//reference parameter
{
	cout << "Enter rate in ml/hr => " ; // problem 1
	cin >> r ;
	cout << "Enter tubing's drop factor(drops/ml) => " ;
	cin >> f ;
}

void getKgRateConc (double&R,double&w,double&c)
{
	cout << "Enter rate in mg/hr => " ; // problem 2
	cin >> R ;
	cout << "Enter patient weight in kg => " ;
	cin >> w ;
	cout << "Enter concentration in mg/ml => ";
	cin >> c ;
}

int figDropsMin (double r, double f)// problem 1
{
	double dM = r * f / 60 ;
	dM = ceil(dM) ;
	return static_cast<int>(dM) ;
}

int byWeight (double R, double w, double c) // problem 2
{
	double mH ;
	mH = R * w * c ;
	mH = ceil (mH) ;
	return static_cast<int>(mH) ;
}
int main ()
{	int n ;
	double r=0, f=0, R=0, w=0, c=0 ;
	cout << "INTRAVENOUS RATE ASSISTANT " << endl ;
	n = getProblem();
	while ((n>=0)||(n<=0)) 
	{
		if(n==1)
		{
			getRateDropFactor(r,f);
			cout << "The drop rate per minute is " << figDropsMin(r,f) << endl ;	
		}
		if (n==2)
		{
			getKgRateConc(R,w,c);
			cout << "The rate in millilitres per hour is " << byWeight(R,w,c) << endl ;
		}
		if (n==3)
		{
			cout << "You have chosen to quit the program. " << endl ;
			cout << "Thank you for using our system. " << endl ;
			break ;
		}
		if ((n<1)||(n>3)) 
		{
			cout << "Please run the system again and choose a problem number between 1 and 3. " << endl ;	
		}
		n = getProblem();
	}
}
