Note that there are some explanatory texts on larger screens.

plurals
  1. POCode not working?
    primarykey
    data
    text
    <p>I am learning <strong><code>C++</code></strong>. As a homework I've started to try the branching.. but I didn't quite get the hang of it... here's the code I've tried to perform (please bear patience with me if I'm making huge mistakes..)</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main () { int age; char * yes; char * no; bool Rated = Rated ? yes : no; int ticketPrice = 5; int discountPrice = ticketPrice - (ticketPrice * 0.1); int matineePrice = (ticketPrice * 0.5); int hour = 8 &lt;= hour &lt;= 24; cout &lt;&lt; "Is the movie R_rated? \n"; cin &gt;&gt; yes or no; cout &lt;&lt; "How old are you?"; cin &gt;&gt; age; if (age &lt; 0 or age &gt;100) { cout &lt;&lt; "Not a valid age!"; } else if ((age &lt;= 13) and (Rated = yes)) { cout &lt;&lt; "You must be accompanied by a Janitor"; } else if (((age &gt; 13) and ((Rated = yes) or (Rated = no))) or ((age &lt;=13) and (Rated = yes))) { cout &lt;&lt; "What time do you want the ticket for?"; cin &gt;&gt; hour; if (hour &lt; 8 or hour &gt; 24) { cout &lt;&lt; "Not a valid hour!"; } else if (hour &lt; 18) { if (age &lt;= 5) { cout &lt;&lt; "The entrance is free"; } else if (age &gt;= 55) { cout &lt;&lt; "Matinee Ticket price is "&lt;&lt; matineePrice; } else if (5 &lt; age &lt; 55) { cout &lt;&lt; "Matinee ticket price is " &lt;&lt; matineePrice; } } else if (hour &gt;= 18) { if (age &lt;= 5) { cout &lt;&lt; "The entrance is free"; } else if (5 &lt; age &lt;= 55) { cout &lt;&lt; "Ticket price is " &lt;&lt; ticketPrice; } else if (age &gt; 55) { cout &lt;&lt; "You're eligibile for a 10% " "discount \n"; cout &lt;&lt; "Ticket price is " &lt;&lt; discountPrice; } } } } </code></pre> <p><strong>Output:</strong> (to which I answer <strong>no</strong>, <strong>67</strong>, and <strong>20</strong>) and I should get the <code>discountedPrice</code> instead of the <code>ticketPrice</code> value...</p> <pre><code>Is the movie R_rated? no How old are you?67 What time do you want the ticket for?20 Ticket price is 5 </code></pre> <p>Any suggestion, link or tutorial help would be really appreciated... </p>
    singulars
    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.
 

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