Priming Sugar Calculator (source code in C)

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

mikegarri

New Member
Joined
Jul 20, 2010
Messages
1
Reaction score
0
Location
Canada
For anyone who's got a bit of background in programming and has access to a C compiler, here's the source code for a priming sugar calculator. I based the program off byo.com 's resource for priming sugar http://byo.com/resources/carbonation. I only programmed it for granulated table sugar (sucrose). The calculator isn't of much more use than the byo article itself, but if you're lazy like me and don't feel like searching for sugar's density every time, this could be of some use. (I haven't programmed in C in a while, so I'm a bit rusty. There shouldn't be any bugs, though.)

Cheers, and happy brewing!

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void main () {

float desired, residual, needed, T, sugarweight, sugarvolume;

printf ("The following program will show how much white granulated sugar (sucrose) to add to the beer for appropriate carbonation. \n \n");
printf ("Style - Volume of CO2 \n");
printf ("American ales - 2.2-3.0 \n");
printf ("British ales - 1.5-2.2 \n");
printf ("German weizens - 2.8-5.1 \n");
printf ("Belgian ales - 2.0-4.5 \n");
printf ("European lagers - 2.4-2.6 \n");
printf ("American lagers - 2.4-2.8 \n");

printf ("Enter desired volume of CO2 \n");
scanf ("%f", &desired);

printf ("Enter the temperature of the beer in degrees Fahrenheit \n");
scanf ("%f", &T);

//residual calculator based on polynomial fitting from the byo.com chart

residual = 0.0001*T*T - 0.0308*T + 2.39;

printf ("The residual CO2 is %f \n", residual);

//sugarweight is in grams
//sugarvolume is in fluid ounces

// 71.4 grams per volume

needed = desired - residual;

sugarweight = needed*71.4;
printf ("The weight of sugar required is %f g \n", sugarweight);

// sucrose density: 1 cup = 8 oz = 200g --wikipedia
// oz per gram = 25 g/oz

sugarvolume = sugarweight/25;

printf ("The volume of sugar is %f fl oz\n", sugarvolume);

}
 

Latest posts

Back
Top