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

bookChallenge: Vending Machine

Compito

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.

Soluzione

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 3
single

single

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

close

bookChallenge: Vending Machine

Scorri per mostrare il menu

Compito

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.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 3
single

single

some-alt