C++ Seconds Minutes Hours when 0
<p>I'm a programming beginner learning C++.</p>

<p>I have some code that will give an output in hours mins and seconds.
Like :</p>

<pre><code>x hours y minutes z seconds
</code></pre>

<p>What I want is that when <code>x, y or z</code> is equal to <code>0</code> to not have that showing up so:<br/>
<code>30hours 0minutes 5seconds</code> would become: <br/>
<code>30hours 5seconds</code>. <br/>
I can do this by using tons of if conditionals but it gets very messed up.
If there's another way please let me know as i really want to learn the right way</p>

<p>Thanks in advance </p>

<p>--EDIT--
This is my actual code</p>

<pre><code>if (hours == 0 &amp;&amp; mins == 0 &amp;&amp; secs != 0) {
    cout &lt;&lt;  secs &lt;&lt; "secs " &lt;&lt; endl;
}
if (hours == 0 &amp;&amp; mins != 0 &amp;&amp; secs == 0) {
    cout &lt;&lt; mins &lt;&lt; "mins " &lt;&lt; endl;
}
if (hours != 0 &amp;&amp; mins == 0 &amp;&amp; secs == 0) {
    cout &lt;&lt; hours &lt;&lt; "hours " &lt;&lt; endl;
}
if (hours == 0 &amp;&amp; mins != 0 &amp;&amp; secs != 0) {
    cout &lt;&lt; mins &lt;&lt; "mins " &lt;&lt; secs &lt;&lt; "secs " &lt;&lt; endl;
}
if (hours != 0 &amp;&amp; mins == 0 &amp;&amp; secs != 0) {
    cout &lt;&lt; hours &lt;&lt; "hours " &lt;&lt; secs &lt;&lt; "secs " &lt;&lt; endl;
}
if (hours != 0 &amp;&amp; mins != 0 &amp;&amp; secs == 0) {
    cout &lt;&lt; hours &lt;&lt; "hours " &lt;&lt; mins &lt;&lt; "mins " &lt;&lt; endl;
}
if (hours != 0 &amp;&amp; mins != 0 &amp;&amp; secs != 0) {
    cout &lt;&lt; hours &lt;&lt; "hours " &lt;&lt; mins &lt;&lt; "mins " &lt;&lt; secs &lt;&lt; "secs " &lt;&lt; endl;
}
</code></pre>

<p>This works but I dont think thats how actual programmers do it.</p>

<p>Here's the second to hour min secs converter </p>

<pre><code>void readabletime(const double a){

hours = a / 3600;
mins = (a/60 - hours * 60);
secs = (a - ((hours * 3600) + (mins * 60)));
</code></pre>

<p>---UPDATE----
I thought of a simpler way to do it with 3 conditionals</p>

<pre><code>if (hours != 0) {
    cout &lt;&lt; hours &lt;&lt; "hours";
}
if (mins != 0) {
    cout &lt;&lt; mins &lt;&lt; "mins"
}
if (secs != 0) {
    cout &lt;&lt; secs &lt;&lt; "secs"
}
</code></pre>