Assert example 1 3
This presentation is the property of its rightful owner.
Sponsored Links
1 / 3

Assert Example (1/3) PowerPoint PPT Presentation


  • 92 Views
  • Uploaded on
  • Presentation posted in: General

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 ;

Download Presentation

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


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 ;

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

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

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


  • Login