int main() {
int i;
int whole_dollar;
struct expense_record august[] = {
1, "Cable (both)", 83.25,
2, "Groceries (both)", 104.90,
5, "Hotel room (hers, travel)", 101.45,
5, "Dinner, drinks (me)", 39.05,
6, "Misc. (hers, travel)", 115.00,
7, "Roses (me)", 32.85,
7, "Dinner, movie, drinks (both)", 99.40,
9, "Airline ticket (hers)", 104.87,
12, "Spare cash and fee (me)", 101.00,
15, "Parking ticket (hers, travel)", 97.00,
16, "Hotel room (hers, travel)", 116.74,
17, "Misc. (hers, travel)", 105.00,
18, "MP3 player (hers, gift to me)", 110.75,
18, "Misc. (hers, travel)", 103,
20, "Pizza delivery (both)", 32.45,
23, "Hotel room (hers, travel)", 111.14,
24, "Spare cash (me)", 110.00,
27, "Roses (me)", 32.85,
27, "Dinner, drinks (both)", 109.50,
28, "Fixing living room window", 101.09,
29, "Replacing dishes", 46.90
};
int august_size = 21;
for (i = 0; i < august_size; i++){
whole_dollar = (int) august[i].cost;
printf("%c ", whole_dollar);
}
printf("\n");
return 0;
}
Realization
is written in C, which is a relatively low-level language.Most of the code involves initializing an expense record for the month of August. (In a more useful program, this information would be read in from a file rather than hard-coded; the effect here is the same, however.) The expenses seem to be for a couple living together. For the most part, they are rather mundane expenses, though patterns of travel, dinner rituals, and indications of conflict can be found.
The purpose of the short
for
loop at first seems to be to print the month's costs in whole dollar amounts on a single line. Doing so would produce this:83 104 101 39 115 32 99 104 101 97 116 105 110 103 32 111 110 32 109 101 46
All data in computer memory is stored as binary--0s and 1s. In a language like C, we must tell the computer what we mean by those values when we print them. For instance, the binary value 01100101 can be printed as a decimal number (101), a hex number (65), or as the character with the corresponding ASCII code ('e'). These are all the same value, simply displayed in a different format or context.
The code here is not printing out the costs as integers, using a "
%d
" formatting code inprintf
. Instead, due to the "%c
", it is printing the character that corresponds to each value. So running the code actually produces this output:Thus that "ah-ha" experience of realization, of seeing the same data in a different light, and drawing a new conclusion.