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

bookChallenge: Vending Machine

Task

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

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 3
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookChallenge: Vending Machine

Swipe to show menu

Task

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 desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 3
single

single

some-alt