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

bookChallenge: Vending Machine

Taak

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.

Oplossing

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 3
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Suggested prompts:

Can you explain this in more detail?

What are the main benefits or drawbacks?

Can you give me an example?

close

bookChallenge: Vending Machine

Veeg om het menu te tonen

Taak

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.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 3
single

single

some-alt