Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Vending Machine | Conditional Control Flow Practice
C Conditional Statements

bookChallenge: Vending Machine

Tehtävä

Swipe to start coding

Create a function getSnackPrice that determines the price of a snack in a vending machine based on the snack type and size.

  • The function should receive two integers: snackType and size.
  • If snackType is 1 (chips):
    • If size is 1, price is 10;
    • If size is 2, price is 15;
    • For any other size, price is 12.
  • If snackType is 2 (chocolate):
    • If size is 1, price is 20;
    • If size is 2, price is 25;
    • For any other size, price is 22.
  • For any other snackType, price is 0.
  • The function should return the price as an integer.

Ratkaisu

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 3
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

close

bookChallenge: Vending Machine

Pyyhkäise näyttääksesi valikon

Tehtävä

Swipe to start coding

Create a function getSnackPrice that determines the price of a snack in a vending machine based on the snack type and size.

  • The function should receive two integers: snackType and size.
  • If snackType is 1 (chips):
    • If size is 1, price is 10;
    • If size is 2, price is 15;
    • For any other size, price is 12.
  • If snackType is 2 (chocolate):
    • If size is 1, price is 20;
    • If size is 2, price is 25;
    • For any other size, price is 22.
  • For any other snackType, price is 0.
  • The function should return the price as an integer.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 3
single

single

some-alt