Note that there are some explanatory texts on larger screens.

plurals
  1. POc++ extracting decimal solution error
    text
    copied!<p>Simple c++ question, so as you can see it creates a table and inputs variable a and also variable t answer, the problem is I don't know how to fix the <code>if ()</code>. As you can see it has an error(typo). I don't know how to identify if variable t has example: <code>1</code> or <code>1.5</code>, if number have 1.(something here and it's bigger than number.<strong>1</strong>) then call one condition else call other. </p> <pre><code>int a,b = 18; double t; for (a = 0; a &lt;= b; a++) { t = 8 + (double)(18 - a) / 2; if (t &gt;= *.1) cout &lt;&lt; setw(9) &lt;&lt; a &lt;&lt; setw(20) &lt;&lt; fixed &lt;&lt; setprecision(1) &lt;&lt; t &lt;&lt; endl; else cout &lt;&lt; setw(9) &lt;&lt; a &lt;&lt; setw(20) &lt;&lt; t &lt;&lt; endl; } </code></pre> <p>Tried :</p> <pre><code>#include &lt;iostream&gt; #include &lt;iomanip&gt; #include &lt;cmath&gt; #include &lt;math.h&gt; using namespace std; int main () { int a,b = 18; double t; for (a = 0; a &lt;= b; a++) { t = 8 + (double)(18 - a) / 2; if (modf(t, NULL) &gt;= 0.1) cout &lt;&lt; setw(9) &lt;&lt; a &lt;&lt; setw(20) &lt;&lt; fixed &lt;&lt; setprecision(1) &lt;&lt; t &lt;&lt; endl; else cout &lt;&lt; setw(9) &lt;&lt; a &lt;&lt; setw(20) &lt;&lt; t &lt;&lt; endl; } } </code></pre> <p>Fixed in my own way, still thanks 'Angew' he was the first to post modf():</p> <pre><code>#include &lt;iostream&gt; #include &lt;iomanip&gt; #include &lt;cmath&gt; #include &lt;math.h&gt; using namespace std; int main () { int a,b = 18; double t,z; int k; for (a = 1; a &lt;= b; a++) { t = 8 + (double)(18 - a) / 2; if (modf(t, &amp;z) &gt;= 0.5) cout &lt;&lt; setw(9) &lt;&lt; a &lt;&lt; setw(20) &lt;&lt; fixed &lt;&lt; setprecision(1) &lt;&lt; t &lt;&lt; endl; else k = t; cout &lt;&lt; setw(9) &lt;&lt; a &lt;&lt; setw(20) &lt;&lt; k &lt;&lt; endl; } } </code></pre>
 

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