I'm trying combine these two programs into one, but I'm having trouble doing so. I always keep getting errors whenever I combine them as a void function. If anyone could step me through this I would appreciate it.
/* Date: 5/8/2019
Purpose: Calculate insulin dosage.
*/
#include <iostream>
usingnamespace std;
int main ()
{
//Step 1: Declare the variables.
int current_BG;
constdouble ideal_BG = 125;
constdouble glucose_Correction = 25;
double mathResults;
//Step 2: Prompt the user to input their current BG.
cout << "What was your current BG (Blood Glucose)?" << endl;
//Wait for the input and store it in current_BG.
cin >> current_BG;
//Step 3: Calculate the Correction Bolus.
mathResults = ((current_BG - ideal_BG) / glucose_Correction);
//Calculate rounded number of the final results as (mathResults + 0.5)
int roundedResults = mathResults + 0.5;
//Step 4
cout << "Your blood glucose is: " << current_BG << " mg/dL.\n";
//Step 5: Declare a IF/ELSE statement for if the current_BG is either
//equal to, greater, or less than the ideal_BG.
if (current_BG == ideal_BG)
{
cout << "You do not need to make any corrections." << endl;
}
elseif (current_BG > ideal_BG)
{
cout << "You need to make corrections.\n";
cout << "You need a dosage of " << mathResults << ", or " << roundedResults << " unit(s) of insulin." << endl;
}
elseif (current_BG < ideal_BG)
{
cout << "You don't need any correction at all! Your BG is low!\n";
cout << "Go drink a soda!" << endl;
}
}
#include <iostream>
usingnamespace std;
int main ()
{
int meal_Carbs;
constdouble carb_Factor = 15;
double calculation;
cout << "What was your total meal carbohydrates?" << endl;
cin >> meal_Carbs;
calculation = (meal_Carbs / carb_Factor);
int roundedCalc = calculation + 0.5;
cout << "Your current carb count is: " << meal_Carbs << " g\n";
if (meal_Carbs < carb_Factor)
{
cout << "You don't need to make any corrections." << endl;
}
elseif (meal_Carbs > carb_Factor)
{
cout << "You need to make corrections.\n";
cout << "You need a dosage of " << calculation << ", or " << roundedCalc << " unit(s) of insulin." << endl;
}
}
I’m guessing you want to combine the total insulin dosage from both programs, yes? So why don’t we just put them one after another, but put both the if else statements at the end of the new combined function. What’s the problem there?
Nah don’t worry about it, yer fine. Also I’m not entirely sure what you mean by "change the int main()",do you mean change them to regular function names or actually change the contents of each of the main functions?
#include <iostream>
usingnamespace std;
void main_insulin ()
{
//Step 1: Declare the variables.
int current_BG;
constdouble ideal_BG = 125;
constdouble glucose_Correction = 25;
double mathResults;
//Step 2: Prompt the user to input their current BG.
cout << "What was your current BG (Blood Glucose)?" << endl;
//Wait for the input and store it in current_BG.
cin >> current_BG;
//Step 3: Calculate the Correction Bolus.
mathResults = ((current_BG - ideal_BG) / glucose_Correction);
//Calculate rounded number of the final results as (mathResults + 0.5)
int roundedResults = mathResults + 0.5;
//Step 4
cout << "Your blood glucose is: " << current_BG << " mg/dL.\n";
//Step 5: Declare a IF/ELSE statement for if the current_BG is either
//equal to, greater, or less than the ideal_BG.
if (current_BG == ideal_BG)
{
cout << "You do not need to make any corrections." << endl;
}
elseif (current_BG > ideal_BG)
{
cout << "You need to make corrections.\n";
cout << "You need a dosage of " << mathResults << ", or " << roundedResults << " unit(s) of insulin." << endl;
}
elseif (current_BG < ideal_BG)
{
cout << "You don't need any correction at all! Your BG is low!\n";
cout << "Go drink a soda!" << endl;
}
}
EDIT: though I do suggest making two .hpp files with prototypes of each func in each day one and include those instead; I personally always get problems when I include cpp files for reasons I don’t really understand. So