Sectionย 4. Chapterย 6
single
Challenge: Practicing With Loops
Swipe to show menu
Task
Swipe to start coding
In a banking system, every customer receives reward points based on their position in the queue. The reward starts at 100 points and increases by 50 points for every subsequent customer. Write a program to calculate and output the reward for the 15th customer using a loop structure.
Implement a method calculateReward that calculates the reward points for a customer:
- Declare a variable
rewardand initialize it with 100. - Use a
forloop that runs from 1 to the value ofcustomerPosition. - On each iteration, add 50 to the
rewardvariable. - Return the final value of
reward.
Example
calculateReward(1) => 100
calculateReward(2) => 150
calculateReward(15) => 800
Solution
Everything was clear?
Thanks for your feedback!
Sectionย 4. Chapterย 6
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat