Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you can use double with a float cast in the loop or you can instanciate your own double type with a custom &lt; operator </p> <pre><code>#include &lt;iostream&gt; using namespace std; class _double { private : double d ; public : _double(double d) { this-&gt;d = d ;} double get() { return d ;} _double &amp;operator+=(_double &amp;a) { this-&gt;d+=a.get(); return *this; } void display(ostream &amp;out) { cout &lt;&lt; this-&gt;d ; } }; bool operator&lt;(_double &amp;a,_double &amp;b) { if ( (float ) a.get() &lt; (float) b.get() ) return true ; return false ; } ostream&amp; operator&lt;&lt;(ostream&amp; out, _double &amp; a) { a.display(out) ; return out; } int main() { double h = 0.2; // stepsize double t_0 = 24; int t_n = 25.; double y_0 = 1; // initial condition _double d1(25); _double d_t(24); _double d_h(0.2); cout &lt;&lt; endl &lt;&lt; " =========== First Method ============== " &lt;&lt; endl ; double t = t_0; while((float) t&lt;(float) t_n) { cout &lt;&lt; "t: " &lt;&lt; t&lt;&lt; endl; cout &lt;&lt; "(t &lt; t_n): " &lt;&lt; (t &lt; t_n) &lt;&lt; endl; t += 0.2; } cout &lt;&lt; " out of loop t: " &lt;&lt; t &lt;&lt; endl; cout &lt;&lt; "out of loop -&gt; (t &lt; t_n): " &lt;&lt; (t &lt; t_n) &lt;&lt; endl; cout &lt;&lt; " =========== Second Method ============== " &lt;&lt; endl ; while( d_t&lt; d1) { cout &lt;&lt; "t: " &lt;&lt; d_t&lt;&lt; endl; cout &lt;&lt; "(t &lt; t_n): " &lt;&lt; (d_t &lt; d1) &lt;&lt; endl; d_t += d_h; } cout &lt;&lt; "out of loop t: " &lt;&lt; t &lt;&lt; endl; cout &lt;&lt; "out of loop -&gt; (t &lt; t_n): " &lt;&lt; (t &lt; t_n) &lt;&lt; endl; return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload