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

bookChallenge: Vending Machine

Tâche

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.

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 3
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

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

Glissez pour afficher le menu

Tâche

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.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 3
single

single

some-alt