/* KHOR YONG XIN (991113-07-6264) SECTION 02
   TEE HUI YOU (001005-10-1332) SECTION 02
   14/11/2019 
   QUESTION 3 */

#include <iostream>
#include <cmath>
using namespace std;

int figDropsMin (float a, float b)
{
	float dropRate;
	
	dropRate = (a/60)*b;
	
	return ceil(dropRate);
}

void getRateDropFactor ()
{
	float dropMLHR, dropFactor;
	int dropRate;
	
	cout << "Enter rate in ml/hr => ";
	cin >> dropMLHR;
	cout << "Enter tubing's drop factor(drops/ml) => ";
	cin >> dropFactor;
	
	dropRate = figDropsMin (dropMLHR, dropFactor);
	
	cout << "The drop rate per minute is " << dropRate << ".\n\n";
}

int byWeight (float a, float b, float c)
{
	int rate;
	
	rate = a*b*c;
	
	return round(rate);
}

void getKgRateConc ()
{
	float rateMGHR, weight, conc;
	int rate;
	
	cout << "Enter rate in mg/kg/hr => ";
	cin >> rateMGHR;
	cout << "Enter patient weight in kg => ";
	cin >> weight;
	cout << "Enter concentration in mg/ml => ";
	cin >> conc;
	
	rate = byWeight (rateMGHR, weight, conc);
	
	cout << "The rate in millilitres per hour is " << rate << ".\n\n";
}

int getProblem ()
{
	int choice;
	 
	cout << "Enter 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\n"
		 << "Problem => ";
	cin >> choice;

	if (choice > 3 || choice < 1)
		cout << "Please run the system again and choose a problem number between 1 and 3.\n";
		
	return choice;
}

int main ()
{
	int choice;
	
	cout << "INTRAVENOUS RATE ASSISTANT\n\n";

	choice = getProblem ();
	
	while (choice > 0 && choice < 4)
	{
		switch (choice)
		{
			case 1	: getRateDropFactor ();
					break;
			case 2	: getKgRateConc();
					break;
			case 3	: cout << "You have chosen to quit the program.\n";
					  cout << "Thank you for using our system.\n";
					return 0;
		}
		choice = getProblem ();
	}
	 
	return 0;
 } 
