/*Nurul Alis Alia Binti Mohamad Zamri Section 2 
  Mirza Sabrina Binti Mohd Salmi*/
  
#include <iostream>
#include<cmath>
using namespace std;
double byWeight(double , double , double );
void getKgRateConc(double &, double &, double &);
double figDropsMin(double , double);
void getRateDropFactor(double &, double &);
int getProblem();

double byWeight(double mghr, double weight, double concentration)
{
	return ceil(mghr*weight*concentration);
}

void getKgRateConc(double &mghr, double &weight, double &concentration)
{
	cout<<"Enter rate in mg/hr => ";
	cin>>mghr;
	cout<<"Enter patient weight in kg => ";
	cin>>weight;
	cout << "Enter concentration in mg/ml => ";
	cin >> concentration;
}

double figDropsMin(double mlhr, double drop)
{
	return ceil((mlhr/60)*drop);
}

void getRateDropFactor(double &mlhr, double &drop)
{
	cout<<"Enter rate in ml/hr => ";
	cin>>mlhr;
	cout<<"Enter tubing's drop factor(drops/ml) => ";
	cin>>drop;
}

int getProblem()
{
	int prob;
	cout<<"INTRAVENOUS RATE ASSISTANT "
		<<"\n\nEnter the number of the problem you wish to solve. "
		<<"\n     GIVEN A MEDICAL ORDER IN            CALCULATE RATE IN "
		<<"\n(1) ml/hr & tubing drop factor             drops/min \n(2) mg/kg/hr & concentration in mg/ml      ml/hr \n(3) QUIT "
		<<"\n\nProblem => ";
	cin>>prob;
	return prob;
}

int main()
{
	int prob;
	double mlhr=0.0,drop=0.0,dropsmin, mghr, weight, concentration,rate;
	
	while(1)
	{
	prob=getProblem();
	if(prob==1)
	{
		getRateDropFactor(mlhr,drop);
		dropsmin=figDropsMin(mlhr,drop);
		cout<<"The drop rate per minute is " << dropsmin;
		cout<<endl<<endl;
	}
	else if (prob==2)
	{
		getKgRateConc(mghr, weight, concentration);
		rate = byWeight (mghr, weight, concentration);
		cout<< "The rate in millilitres per hour is "<< rate;
		cout<<endl<<endl;
	}
	else
		break;
	}
	if (prob==3)
		cout<<"You have chosen to quit the program.\nThank you for using our system.";
	
	if(prob!=1&&prob!=2&&prob!=3)
		cout<<"Please run the system again and choose a problem number between 1 and 3. ";
	
	return 0;
}
