Difference between revisions of "CPP/Debugging/Assert"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) m (moved CPP/Assert to CPP/Debugging/Assert) |
Daviddoria (Talk | contribs) (Undo revision 699 by 188.143.232.65 (Talk)) |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 3: | Line 3: | ||
<source lang="cpp"> | <source lang="cpp"> | ||
#include <iostream> | #include <iostream> | ||
| − | #include < | + | #include <cassert> |
| + | #include <string> | ||
| + | #include <cmath> | ||
| − | + | using namespace std; | |
| − | { | + | |
| − | + | float Sqrt(float n){ | |
| − | + | assert(n >= 0); | |
| − | + | return sqrt(n); | |
| − | + | } | |
| + | int main(){ | ||
| + | |||
| + | Sqrt(16); //pass | ||
| + | Sqrt(-16); //fail | ||
| + | |||
return 0; | return 0; | ||
} | } | ||
</source> | </source> | ||
Latest revision as of 08:23, 11 February 2011
Assert.cpp
#include <iostream> #include <cassert> #include <string> #include <cmath> using namespace std; float Sqrt(float n){ assert(n >= 0); return sqrt(n); } int main(){ Sqrt(16); //pass Sqrt(-16); //fail return 0; }