Difference between revisions of "CPP/Debugging/Assert"
From ProgrammingExamples
< CPP
(EbYi0H <a href="http://fkjulsrgrqbq.com/">fkjulsrgrqbq</a>, [url=http://dwnviizobnyk.com/]dwnviizobnyk[/url], [link=http://ckskjrcqipjr.com/]ckskjrcqipjr[/link], http://bsopxewxrsnc.com/) |
Daviddoria (Talk | contribs) (Undo revision 699 by 188.143.232.65 (Talk)) |
||
| Line 1: | Line 1: | ||
| − | + | ==Assert.cpp== | |
| + | |||
| + | <source lang="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; | ||
| + | } | ||
| + | |||
| + | </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; }