I'm planning on starting a CKD diet within the next moth and was a little bored today so i wrote a program to do all the calculations for me. You input your current weight and the number of meals you plan to eat per day and the program calculates, based on the ratios from Mr. X's article how much fat and protein to eat.
I don't have any hosting so all I can post is the source code. So just put it in a C compiler and compile it. If anyone wants to host the exe file (it's only 7Kb) thats fine with me)
I'm sure its not the most efficient code but it does the job.
The program outputs a text file with all the results.
I don't have any hosting so all I can post is the source code. So just put it in a C compiler and compile it. If anyone wants to host the exe file (it's only 7Kb) thats fine with me)
I'm sure its not the most efficient code but it does the job.
The program outputs a text file with all the results.
Code:
#include <stdio.h>
main()
{
FILE *fptr;
int weight, meals;
//day 1 var
float bmr, f1, p1, cal1, fg1, pg1, fgpm1, pgpm1;
//day 2 var
float f2, p2, cal2, fg2, pg2, fgpm2, pgpm2;
//day 3 var
float f3, p3, cal3, fg3, pg3, fgpm3, pgpm3;
//day 4 var
float f4, p4, cal4, fg4, pg4, fgpm4, pgpm4;
//day 5 var
float f5, p5, cal5, fg5, pg5, fgpm5, pgpm5;
//day 6 var
float f6, p6, cal6, fg6, pg6, fgpm6, pgpm6;
//carb up
float cbmr, fg7, pg7, f7, p7, cal7, carb, carbg, carbgpm, fgpm7, pgpm7;
if((fptr = fopen("ckd.txt", "w")) == NULL)
printf("File could not be opened.\n");
else {
printf("\t*************************************\n");
printf("\t* CKD Diet Calculator *\n");
printf("\t*************************************\n");
printf("\n\nEnter your weight: ");
scanf("%d", &weight);
printf("\nEnter the number of meals to eat per day: ");
scanf("%d", &meals);
bmr = weight * 12;
fprintf(fptr, "\t*************************************\n");
fprintf(fptr, "\t* CKD Diet Paramaters *\n");
fprintf(fptr, "\t*************************************\n");
fprintf(fptr, "\nYour Basal Metabolic Rate, BMR is: %.0f", bmr);
//day 1
cal1 = (bmr * -0.05) + bmr;
f1 = cal1 * 0.85;
p1 = cal1 * 0.15;
fg1 = f1/9;
pg1 = p1/4;
fgpm1 = fg1/meals;
pgpm1 = pg1/meals;
fprintf(fptr, "\n\n[DAY 1]\t\tTotal Calories: %.0f\n\n", cal1);
fprintf(fptr, "Calories from fat: \t%.0f\t\tGrams of fat: \t\t %.0f\n", f1, fg1);
fprintf(fptr, "Calories from Protein: \t%.0f\t\tGrams of protein: \t %.0f\n", p1, pg1);
fprintf(fptr, "Grams of fat per meal: \t%.0f\t\tGrams of protein per meal: %.0f\n", fgpm1, pgpm1);
//day 2
cal2 = (bmr * -0.10) + bmr;
f2 = cal2 * 0.75;
p2 = cal2 * 0.25;
fg2 = f2/9;
pg2 = p2/4;
fgpm2 = fg2/meals;
pgpm2 = pg2/meals;
fprintf(fptr, "\n\n[DAY 2]\t\tTotal Calories: %.0f\n\n", cal2);
fprintf(fptr, "Calories from fat: \t%.0f\t\tGrams of fat: \t\t %.0f\n", f2, fg2);
fprintf(fptr, "Calories from Protein: \t%.0f\t\tGrams of protein: \t %.0f\n", p2, pg2);
fprintf(fptr, "Grams of fat per meal: \t%.0f\t\tGrams of protein per meal: %.0f\n", fgpm2, pgpm2);
//day 3
cal3 = (bmr * -0.15) + bmr;
f3 = cal3 * 0.65;
p3 = cal3 * 0.35;
fg3 = f3/9;
pg3 = p3/4;
fgpm3 = fg3/meals;
pgpm3 = pg3/meals;
fprintf(fptr, "\n\n[DAY 3]\t\tTotal Calories: %.0f\n\n", cal3);
fprintf(fptr, "Calories from fat: \t%.0f\t\tGrams of fat: \t\t %.0f\n", f3, fg3);
fprintf(fptr, "Calories from Protein: \t%.0f\t\tGrams of protein: \t %.0f\n", p3, pg3);
fprintf(fptr, "Grams of fat per meal: \t%.0f\t\tGrams of protein per meal: %.0f\n", fgpm3, pgpm3);
//day 4
cal4 = bmr;
f4 = cal4 * 0.70;
p4 = cal4 * 0.30;
fg4 = f4/9;
pg4 = p4/4;
fgpm4 = fg4/meals;
pgpm4 = pg4/meals;
fprintf(fptr, "\n\n[DAY 4]\t\tTotal Calories: %.0f\n\n", cal4);
fprintf(fptr, "Calories from fat: \t%.0f\t\tGrams of fat: \t\t %.0f\n", f4, fg4);
fprintf(fptr, "Calories from Protein: \t%.0f\t\tGrams of protein: \t %.0f\n", p4, pg4);
fprintf(fptr, "Grams of fat per meal: \t%.0f\t\tGrams of protein per meal: %.0f\n", fgpm4, pgpm4);
//day 5
cal5 = (bmr * -0.10) + bmr;
f5 = cal5 * 0.70;
p5 = cal5 * 0.30;
fg5 = f5/9;
pg5 = p5/4;
fgpm5 = fg5/meals;
pgpm5 = pg5/meals;
fprintf(fptr, "\n\n[DAY 5]\t\tTotal Calories: %.0f\n\n", cal5);
fprintf(fptr, "Calories from fat: \t%.0f\t\tGrams of fat: \t\t %.0f\n", f5, fg5);
fprintf(fptr, "Calories from Protein: \t%.0f\t\tGrams of protein: \t %.0f\n", p5, pg5);
fprintf(fptr, "Grams of fat per meal: \t%.0f\t\tGrams of protein per meal: %.0f\n", fgpm5, pgpm5);
//day 6
cal6 = (bmr * -0.15) + bmr;
f6 = cal6 * 0.65;
p6 = cal6 * 0.35;
fg6 = f6/9;
pg6 = p6/4;
fgpm6 = fg6/meals;
pgpm6 = pg6/meals;
fprintf(fptr, "\n\n[DAY 6]\t\tTotal Calories: %.0f\n\n", cal6);
fprintf(fptr, "Calories from fat: \t%.0f\t\tGrams of fat: \t\t %.0f\n", f6, fg6);
fprintf(fptr, "Calories from Protein: \t%.0f\t\tGrams of protein: \t %.0f\n", p6, pg6);
fprintf(fptr, "Grams of fat per meal: \t%.0f\t\tGrams of protein per meal: %.0f\n", fgpm6, pgpm6);
//carb up
cbmr = (bmr * 0.3) + bmr;
f7 = cbmr * 0.1;
p7 = cbmr * 0.2;
carb = cbmr * 0.7;
fg7 = f7/9;
pg7 = p7/4;
carbg = carb/4;
fgpm7 = fg7/meals;
pgpm7 = pg7/meals;
carbgpm = carbg/meals;
fprintf(fptr, "\n\n[DAY 7]\t\tTotal Calories: %.0f\n\n", cbmr);
fprintf(fptr, "Calories from fat: \t%.0f\t\tGrams of fat: \t\t %.0f\n", f7, fg7);
fprintf(fptr, "Calories from Protein: \t%.0f\t\tGrams of protein: \t %.0f\n", p7, pg7);
fprintf(fptr, "Calories from Carbs: \t%.0f\t\tGrams of Carbs: \t %.0f\n", carb, carbg);
fprintf(fptr, "Grams of fat per meal: \t%.0f\t\tGrams of protein per meal: %.0f\n", fgpm7, pgpm7);
fprintf(fptr, "Grams of carb per meal: %.0f\n", carbgpm);
fclose(fptr);
}
return 0;
}
Last edited:

Please Scroll Down to See Forums Below 










