30 likes | 220 Views
Assert Example (1/3). /***************************************** Program: beers.c How many beers are left after 5 rounds? *****************************************/ #include <stdio.h> #include <assert.h> int main() { /* Declare variable */ float beers ;
E N D
Assert Example (1/3) /***************************************** Program: beers.c How many beers are left after 5 rounds? *****************************************/ #include <stdio.h> #include <assert.h> int main() { /* Declare variable */ float beers ; for (beers = 1.0; beers != 0.0; beers -= 0.2) { assert ( beers > 0.0 ); printf("%f %s\n%f %s\n", beers, "bottles of beer on the wall", beers, "bottles of beer"); printf("Take a fifth down, pass it around\n"); printf("%e bottles of beer on the wall\n\n", beers - 0.2 ); } return 0; }
Assert Example (2/3) ecs122pc37-lx-(12:38pm): gcc -Wall -ansi beers.c ecs122pc37-lx-(12:38pm): a.out 1.000000 bottles of beer on the wall 1.000000 bottles of beer Take a fifth down, pass it around 8.000000e-01 bottles of beer on the wall 0.800000 bottles of beer on the wall 0.800000 bottles of beer Take a fifth down, pass it around 6.000000e-01 bottles of beer on the wall 0.600000 bottles of beer on the wall 0.600000 bottles of beer Take a fifth down, pass it around 4.000000e-01 bottles of beer on the wall 0.400000 bottles of beer on the wall 0.400000 bottles of beer Take a fifth down, pass it around 2.000000e-01 bottles of beer on the wall
Assert Example (3/3) 0.200000 bottles of beer on the wall 0.200000 bottles of beer Take a fifth down, pass it around 3.278255e-08 bottles of beer on the wall 0.000000 bottles of beer on the wall 0.000000 bottles of beer Take a fifth down, pass it around -2.000000e-01 bottles of beer on the wall a.out: beers.c:22: main: Assertion `beers > 0.0' failed. Abort ecs122pc37-lx-(12:38pm):