{"id":6193,"date":"2021-09-08T11:20:47","date_gmt":"2021-09-08T09:20:47","guid":{"rendered":"https:\/\/blue.pri.ee\/ttu\/?p=6193"},"modified":"2025-09-11T20:40:44","modified_gmt":"2025-09-11T18:40:44","slug":"2-lab-conditional-statements","status":"publish","type":"post","link":"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/","title":{"rendered":"PR1EN2: Conditional statements"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/#Lab_materials\" >Lab materials<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/#Tasks\" >Tasks<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/#Task_1_W02-1_Cash_register\" >Task 1 [W02-1]: Cash register<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/#Requirements\" >Requirements:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/#Testing\" >Testing<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/#Task_2_W02-2_Food_scale\" >Task 2 [W02-2]: Food scale<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/#Requirements-2\" >Requirements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/#Algorithm\" >Algorithm<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/#Testing-2\" >Testing<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/#Extra_task_W02-3_Bonus_account\" >Extra task [W02-3]: Bonus account<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/#Requirements-3\" >Requirements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/#Necessary_knowledge\" >Necessary knowledge<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/#Testing-3\" >Testing<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/#Additional_content\" >Additional content<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Lab_materials\"><\/span><strong>Lab materials<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Slides:\u00a0<a href=\"https:\/\/blue.pri.ee\/ttu\/files\/iax0583\/slaidid-en\/02_conditionals_continued.pdf\"><strong>Conditional statements 2<\/strong><\/a><\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Tasks\"><\/span>Tasks<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>This lab has two base tasks, first one simulating a cash register and the second one simulating a store food scale. The first task is extended by an extra task, adding support for bonus point management.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Task_1_W02-1_Cash_register\"><\/span>Task 1 [W02-1]: Cash register<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>With this task, we&#8217;ll create a simple cash register application with the goal of trying to compose different conditional statements. The task is provided with a starter code to start you off. Base your solution on the starter code, write your code statements after the comments specifying what to do!<\/p>\n<h5><span class=\"ez-toc-section\" id=\"Requirements\"><\/span><strong>Requirements:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h5>\n<ul>\n<li>Program must be logically identical to the given algorithm<\/li>\n<li>Program must be built on the base code given. Your task is to add the missing <span class=\"lang:default highlight:0 decode:true crayon-inline \">printf<\/span> , <span class=\"lang:default highlight:0 decode:true crayon-inline\">scanf<\/span> , conditional statements and calculations. Use the code comments and the activity diagram as a reference.<\/li>\n<li>Don&#8217;t change the variable naming or the program structure<\/li>\n<li><strong>Recommendation<\/strong>: To check that the values are correctly read and program behaves as expected, add printouts to check the variable values after mathematical operations.<\/li>\n<\/ul>\n<p><strong>Download task 1 starter code<\/strong>: [<a style=\"cursor: pointer !important; user-select: none !important;\" href=\"https:\/\/blue.pri.ee\/ttu\/files\/iax0583\/aluskoodid\/2_1_kassa_baas.c\"><strong>et<\/strong><\/a>] [<strong><a href=\"https:\/\/blue.pri.ee\/ttu\/files\/iax0583\/aluskoodid\/2_1_cashier_base.c\">en<\/a><\/strong>]\n<p><strong>Algorithm<\/strong><\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2021\/09\/2_kassa_en.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-10557 size-full\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2021\/09\/2_kassa_en.png\" alt=\"\" width=\"1384\" height=\"1088\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2021\/09\/2_kassa_en.png 1384w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2021\/09\/2_kassa_en-300x236.png 300w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2021\/09\/2_kassa_en-1024x805.png 1024w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2021\/09\/2_kassa_en-768x604.png 768w\" sizes=\"auto, (max-width: 1384px) 100vw, 1384px\" \/><\/a><\/p>\n<h5><span class=\"ez-toc-section\" id=\"Testing\"><\/span><strong>Testing<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>I&#8217;m proposing a series of tests for the program you are about to create. NB! I&#8217;ve left at least one important test case untested. Can you figure out which one?<\/p>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-chevron su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>Click me to see the test cases!<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n<p><strong>Test 1:\u00a0<\/strong>Client is not offered any discount, successfully completes the payment. Also testing floating point values.<\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true \" title=\"Sample\">Enter purchase total: 44.99\r\nDid client present loyalty card?\r\n1 - yes\r\n0 - no\r\n0\r\n\r\nApply extra discount?\r\n1 - yes\r\n0 - no\r\n0\r\n\r\nInvoice total: 44.99\r\n\r\nPlease enter card PIN code: 1234\r\nPIN code accepted!\r\n\r\nPurchase complete!\r\nNew account balance is 55.01<\/pre>\n<p><strong>Test 2:\u00a0<\/strong>Client has the loyalty card and gets an extra discount.<\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"Sample\">Enter purchase total: 89.99\r\nDid client present loyalty card?\r\n1 - yes\r\n0 - no\r\n1\r\n\r\nApply extra discount?\r\n1 - yes\r\n0 - no\r\n1\r\n\r\nInvoice total: 71.99\r\n\r\nPlease enter card PIN code: 1234\r\nPIN code accepted!\r\n\r\nPurchase complete!\r\nNew account balance is 28.01<\/pre>\n<p><strong>Test 3:\u00a0<\/strong>Client has exactly the required amount of assets on their card.<\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"Sample\">Enter purchase total: 100\r\nDid client present loyalty card?\r\n1 - yes\r\n0 - no\r\n0\r\n\r\nApply extra discount?\r\n1 - yes\r\n0 - no\r\n0\r\n\r\nInvoice total: 100.00\r\n\r\nPlease enter card PIN code: 1234\r\nPIN code accepted!\r\n\r\nPurchase complete!\r\nNew account balance is 0.00\r\n<\/pre>\n<p><strong>Test 4:\u00a0<\/strong>Client that is only able to afford the purchase after the discount.<\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"Sample\">Enter purchase total: 105\r\nDid client present loyalty card?\r\n1 - yes\r\n0 - no\r\n1\r\n\r\nApply extra discount?\r\n1 - yes\r\n0 - no\r\n0\r\n\r\nInvoice total: 94.50\r\n\r\nPlease enter card PIN code: 1234\r\nPIN code accepted!\r\n\r\nPurchase complete!\r\nNew account balance is 5.50<\/pre>\n<p><strong>Test 5:<\/strong> Client with not enough assets.<\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"Sample\">Enter purchase total: 110\r\nDid client present loyalty card?\r\n1 - yes\r\n0 - no\r\n0\r\nApply extra discount?\r\n1 - yes\r\n0 - no\r\n0\r\nInvoice total: 110.00\r\n\r\nPlease enter card PIN code: 1234\r\nPIN code accepted!\r\n\r\nError! Not enough assets on the card!<\/pre>\n<p><strong>Test 6:\u00a0<\/strong>Client, who does not know their PIN code.<\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"Sample\">Enter purchase total: 50\r\nDid client present loyalty card?\r\n1 - yes\r\n0 - no\r\n1\r\n\r\nApply extra discount?\r\n1 - yes\r\n0 - no\r\n1\r\n\r\nInvoice total: 40.00\r\n\r\nPlease enter card PIN code: 9999\r\nError! Incorrect PIN code!<\/pre>\n<\/div><\/div>\n<h4><span class=\"ez-toc-section\" id=\"Task_2_W02-2_Food_scale\"><\/span>Task 2 [W02-2]: Food scale<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>In this task you will create a program, that simulates the food scale in a grocery store.<\/p>\n<p><strong>The UML activity diagram to structure your program on will be created in class.<\/strong> Your program must match or exceed the functionality described.<\/p>\n<h5><span class=\"ez-toc-section\" id=\"Requirements-2\"><\/span>Requirements<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<ul>\n<li>You must have at least four products available.<\/li>\n<li>Products are represented as pairs of product codes (integer) and names (e.g. 1 &#8211; banana).<\/li>\n<li>The user inputs an integer product code and a real numbered quantity (in kilograms) from the keyboard.<\/li>\n<li>You must handle matching the product code to the price of 1 kg in the <span class=\"lang:default highlight:0 decode:true crayon-inline \">switch<\/span>\u00a0 statement.<\/li>\n<li>User will be displayed the total price only if a valid product code and weight are entered.<\/li>\n<li>The given price(s) must be given with 2 decimal places.<\/li>\n<li>Invalid product code and weight must trigger an error. There is no need to specify which error occurred. In case of an error, price must not be shown!<\/li>\n<\/ul>\n<p><strong>Download the starter code for task 2: <a href=\"https:\/\/blue.pri.ee\/ttu\/files\/iax0583\/aluskoodid\/2_2_scale_base.c\">2_2_scale_base.c<\/a><\/strong><\/p>\n<h5><span class=\"ez-toc-section\" id=\"Algorithm\"><\/span>Algorithm<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>A copy of the algorithm for those who either reach the second task more quickly during the lesson or lose their own copy of the algorithm. The algorithm will also be solved together in class with additional commentary<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2021\/09\/2_2_kaal_en.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10593\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2021\/09\/2_2_kaal_en.png\" alt=\"\" width=\"1084\" height=\"848\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2021\/09\/2_2_kaal_en.png 1084w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2021\/09\/2_2_kaal_en-300x235.png 300w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2021\/09\/2_2_kaal_en-1024x801.png 1024w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2021\/09\/2_2_kaal_en-768x601.png 768w\" sizes=\"auto, (max-width: 1084px) 100vw, 1084px\" \/><\/a><\/p>\n<h5><span class=\"ez-toc-section\" id=\"Testing-2\"><\/span><strong>Testing<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p><strong>Test 1:<\/strong> Correct inputs will give us a total cost.<\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"Sample 1: correct inputs, price output\">             Available products\r\n1 - Banana      2 - Orange      3 - Lemon      \r\n4 - Tomato      5 - Cucumber    6 - Potato     \r\n7 - Apple       8 - Pear        9 - Plum       \r\n\r\nEnter weight (kg): 2.5\r\nEnter product code: 4\r\n\r\nSelected product 4 - Tomato\r\n\r\nEntered weight: 2.5 kg\r\nPrice per kilo 1.49 EUR\r\nTotal price: 3.73 EUR\r\n<\/pre>\n<p><strong>Test 2:<\/strong> Invalid product code triggers an error.<\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"Sample 2: code error\">           Available products\r\n1 - Banana      2 - Orange      3 - Lemon      \r\n4 - Tomato      5 - Cucumber    6 - Potato     \r\n7 - Apple       8 - Pear        9 - Plum       \r\n\r\nEnter weight (kg): 2.1\r\nEnter product code: 53\r\n\r\nError! Unknown product code! Exiting ..\r\n<\/pre>\n<p><strong>Test 3:<\/strong> Invalid weight triggers an error.<\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"Sample 3: weight error\">           Available products\r\n1 - Banana      2 - Orange      3 - Lemon      \r\n4 - Tomato      5 - Cucumber    6 - Potato     \r\n7 - Apple       8 - Pear        9 - Plum       \r\n\r\nEnter weight (kg): -4\r\n\r\nError! Invalid weight! Exiting ..\r\n<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"Extra_task_W02-3_Bonus_account\"><\/span>Extra task [W02-3]: Bonus account<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>The extra task is an extension of the first task. To do this, we\u2019ll add an option for the user to use bonus points.<\/p>\n<p>While solving the task, think carefully about <strong>everything that could go wrong at each stage of the transaction and how those issues are related!<\/strong><\/p>\n<p>Note: as a result of solving this task, you will end up with one long piece of spaghetti code \u2014 everything in a single function. We will start fighting against this from fourth week.<\/p>\n<h5><span class=\"ez-toc-section\" id=\"Requirements-3\"><\/span><strong>Requirements<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h5>\n<ul>\n<li>Add user&#8217;s bonus points count to the program, it should be initialized.\u00a0Bonus points can only be integers (e.g., 1 bonus point, 15 bonus points).<\/li>\n<li>Before completing a transaction, the user is shown their total bonus points and the maximum number of points they are allowed to use for this purchase, according to the rules of using\u00a0 bonus point.<\/li>\n<li>Then the user is asked whether they want to use bonus points. If yes, the program asks how many they wish to use.<\/li>\n<li>Bonus point rules\n<ul>\n<li>1 bonus point equals 1 euro cent<\/li>\n<li>A maximum of 90% of the purchase can be paid with bonus points, calculated after discounts<\/li>\n<li>If the user enters a number of bonus points greater than what they have or greater than what is allowed for the purchase, the maximum permitted amount is used instead<\/li>\n<\/ul>\n<\/li>\n<li>The rest of the transaction logic remains as specified by the base task<\/li>\n<li>At the end of the transaction, the user is shown the remaining balance of their bonus account<\/li>\n<\/ul>\n<h5><span class=\"ez-toc-section\" id=\"Necessary_knowledge\"><\/span>Necessary knowledge<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<article class=\"text-token-text-primary w-full focus:outline-none scroll-mt-[calc(var(--header-height)+min(200px,max(70px,20svh)))]\" dir=\"auto\" tabindex=\"-1\" data-turn-id=\"request-WEB:aa1f44ec-ba1e-4bf5-9551-93ae31785825-7\" data-testid=\"conversation-turn-16\" data-scroll-anchor=\"true\" data-turn=\"assistant\">\n<div class=\"text-base my-auto mx-auto pb-10 [--thread-content-margin:--spacing(4)] thread-sm:[--thread-content-margin:--spacing(6)] thread-lg:[--thread-content-margin:--spacing(16)] px-(--thread-content-margin)\">\n<div class=\"[--thread-content-max-width:40rem] thread-sm:[--thread-content-max-width:40rem] thread-lg:[--thread-content-max-width:48rem] mx-auto max-w-(--thread-content-max-width) flex-1 group\/turn-messages focus-visible:outline-hidden relative flex w-full min-w-0 flex-col agent-turn\" tabindex=\"-1\">\n<div class=\"flex max-w-full flex-col grow\">\n<div class=\"min-h-8 text-message relative flex w-full flex-col items-end gap-2 text-start break-words whitespace-normal [.text-message+&amp;]:mt-5\" dir=\"auto\" data-message-author-role=\"assistant\" data-message-id=\"4eefa3e2-b7ab-40d7-b954-ffa964bd24d2\" data-message-model-slug=\"gpt-5\">\n<div class=\"flex w-full flex-col gap-1 empty:hidden first:pt-[3px]\">\n<div class=\"markdown prose dark:prose-invert w-full break-words dark markdown-new-styling\">\n<p data-start=\"0\" data-end=\"346\" data-is-last-node=\"\" data-is-only-node=\"\">As a reminder from the previous lesson \u2013 the quotient of two integers is always an integer. If you need a division where the result must be a floating-point number (i.e., a number with a decimal point), then at least one of the numbers involved in the division must be a floating-point number. This turns the entire operation into a fractional division.<\/p>\n<p data-start=\"0\" data-end=\"346\" data-is-last-node=\"\" data-is-only-node=\"\">For example, 1 \/ 100 gives the integer 0, but 1.0 \/ 100 gives the floating-point number 0.01.<\/p>\n<p data-start=\"0\" data-end=\"346\" data-is-last-node=\"\" data-is-only-node=\"\">When multiplying by a real number, this issue does not occur \u2014 e.g., 10 * 0.01 results in 0.1.<\/p>\n<h5><span class=\"ez-toc-section\" id=\"Testing-3\"><\/span>Testing<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>In the first example, the user is applied discount. Without the discount, the purchase would not be possible.<\/p>\n<pre class=\"theme:cisco-router toolbar:2 nums:false lang:c highlight:0 decode:true\">Enter purchase total: 125\r\n\r\nDid client present loyalty card?\r\n1 - yes\r\n0 - no\r\n1\r\n\r\nApply extra discount?\r\n1 - yes\r\n0 - no\r\n0\r\n\r\n10% discount applied\r\nInvoice total: 112.50\r\n\r\nYou currently have 10000 bonus points\r\nFor this purchase, you can use up to 10000 points\r\n\r\nDo you wish to use bonus points?\r\n1 - yes\r\n0 - no\r\n1\r\n\r\nEnter the number of bonus points to use: 3500\r\n\r\nPoints used for this purchase: 3500\r\nAmount to be paid after points: 77.50 EUR\r\n\r\nPlease enter your PIN code:1234\r\nPIN code accepted!\r\nPurchase completed!\r\n\r\nFinal card balance is 22.50 EUR\r\nFinal amount of bonus points left: 6500\r\n<\/pre>\n<p>In the second example, the user chooses not to use their bonus points.<\/p>\n<pre class=\"theme:cisco-router toolbar:2 nums:false lang:c highlight:0 decode:true\">Enter purchase total: 9.69\r\n\r\nDid client present loyalty card?\r\n1 - yes\r\n0 - no\r\n1\r\n\r\nApply extra discount?\r\n1 - yes\r\n0 - no\r\n1\r\n\r\n20% discount applied\r\nInvoice total: 7.75\r\n\r\nYou currently have 7500 bonus points\r\nFor this purchase, you can use up to 697 points\r\n\r\nDo you wish to use bonus points?\r\n1 - yes\r\n0 - no\r\n0\r\n\r\n\r\nPlease enter your PIN code:1234\r\nPIN code accepted!\r\nPurchase completed!\r\n\r\nFinal card balance is 92.25 EUR\r\nFinal amount of bonus points left: 7500\r\n<\/pre>\n<p>In this example, the user wants to use more bonus points than they have, so the amount is overwritten. The transaction does not go through because there is not enough money, and the bonus point balance remains unchanged.<\/p>\n<pre class=\"theme:cisco-router toolbar:2 nums:false lang:c highlight:0 decode:true\">Enter purchase total: 139.99\r\n\r\nDid client present loyalty card?\r\n1 - yes\r\n0 - no\r\n1\r\n\r\nApply extra discount?\r\n1 - yes\r\n0 - no\r\n1\r\n\r\n20% discount applied\r\nInvoice total: 111.99\r\n\r\nYou currently have 350 bonus points\r\nFor this purchase, you can use up to 350 points\r\n\r\nDo you wish to use bonus points?\r\n1 - yes\r\n0 - no\r\n1 \r\n\r\nEnter the number of bonus points to use: 2000\r\nError! This exceeds the maximum allowed!\r\nUsing maximum amount of 350 points\r\n\r\nPoints used for this purchase: 350\r\nAmount to be paid after points: 108.49 EUR\r\n\r\nPlease enter your PIN code:1234\r\nPIN code accepted!\r\nError! Not enough balance on the card!\r\n\r\nFinal card balance is 100.00 EUR\r\nFinal amount of bonus points left: 350\r\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div><strong style=\"font-size: 22px;\">After the class, you should\u00a0<\/strong><\/div>\n<\/div>\n<\/div>\n<\/article>\n<ul>\n<li>Know what is a truth table and how to read them<\/li>\n<li>Be able to form conditional statements consisting of multiple conditions<\/li>\n<li>Know what De Morgan&#8217;s law is and how to apply it<\/li>\n<li>Know how to use inversion and short forms for conditional statements<\/li>\n<li>Be able to initialize integers and floating point values when declaring them<\/li>\n<li>Be able to write nested conditional statements<\/li>\n<li>Be able to alter the variable value relative to the old value, on the same line<\/li>\n<li>Be able to use and print floating point values while specifying number of decimal places<\/li>\n<li>Understand how switch statements work and how to use them in code<\/li>\n<li>Be able to model a switch statement in an activity diagram<\/li>\n<li>Know how to use swim lanes<\/li>\n<li>Know how to have multiple different endings in both programs and in activity diagrams<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Additional_content\"><\/span><strong>Additional content<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>De Morgan&#8217;s Laws<br \/>\n<strong><a style=\"cursor: pointer !important; user-select: none !important;\" href=\"https:\/\/brilliant.org\/wiki\/de-morgans-laws\/\">https:\/\/brilliant.org\/wiki\/de-morgans-laws\/<\/a><\/strong><\/li>\n<li>C\/C++ if else if ladder with Examples<br \/>\n<strong><a href=\"https:\/\/www.geeksforgeeks.org\/c-c-if-else-if-ladder-with-examples\/\">https:\/\/www.geeksforgeeks.org\/c-c-if-else-if-ladder-with-examples\/<\/a><\/strong><\/li>\n<li>Decision Making in C \/ C++ (if , if..else, Nested if, if-else-if )<br \/>\n<strong><a href=\"https:\/\/www.geeksforgeeks.org\/decision-making-c-c-else-nested-else\/\">https:\/\/www.geeksforgeeks.org\/decision-making-c-c-else-nested-else\/<\/a><\/strong><\/li>\n<li>Exit codes in C\/C++ with Examples<br \/>\n<strong><a href=\"https:\/\/www.geeksforgeeks.org\/exit-codes-in-c-c-with-examples\/\">https:\/\/www.geeksforgeeks.org\/exit-codes-in-c-c-with-examples\/<\/a><\/strong><\/li>\n<li>Beej&#8217;s guide: switch statement<br \/>\n<strong><a href=\"https:\/\/beej.us\/guide\/bgc\/html\/split\/variables-and-statements.html#switch-statement\">https:\/\/beej.us\/guide\/bgc\/html\/split\/variables-and-statements.html#switch-statement<\/a><\/strong><\/li>\n<li>Switch Statement in C\/C++<br \/>\n<strong><a href=\"https:\/\/www.geeksforgeeks.org\/switch-statement-cc\/\">https:\/\/www.geeksforgeeks.org\/switch-statement-cc\/<\/a><\/strong><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Lab materials Slides:\u00a0Conditional statements 2 Tasks This lab has two base tasks, first one simulating a cash register and the second one simulating a store food scale. The first task is extended by an extra task, adding support for bonus point management. Task 1 [W02-1]: Cash register With this task, we&#8217;ll create a simple cash &hellip; <a href=\"https:\/\/blue.pri.ee\/ttu\/labs\/2-lab-conditional-statements\/\" class=\"more-link\">Loe edasi <span class=\"screen-reader-text\">PR1EN2: Conditional statements<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75,77],"tags":[],"class_list":["post-6193","post","type-post","status-publish","format-standard","hentry","category-labs","category-pr1_en"],"_links":{"self":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/posts\/6193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/comments?post=6193"}],"version-history":[{"count":26,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/posts\/6193\/revisions"}],"predecessor-version":[{"id":10606,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/posts\/6193\/revisions\/10606"}],"wp:attachment":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/media?parent=6193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/categories?post=6193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/tags?post=6193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}