1 / 3

Assert Example (1/3)

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 ;

petula
Télécharger la présentation

Assert Example (1/3)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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; }

  2. 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

  3. 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):

More Related