Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Practicing With Loops | Introduction to Program Flow
C++ Introduction

bookChallenge: Practicing With Loops

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 reward and initialize it with 100.
  • Use a for loop that runs from 1 to the value of customerPosition.
  • On each iteration, add 50 to the reward variable.
  • Return the final value of reward.

Example

calculateReward(1) => 100
calculateReward(2) => 150
calculateReward(15) => 800

Solution

solution.cpp

solution.cpp

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 6
single

single

Ask AI

expand

Ask AI

ChatGPT

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

close

Awesome!

Completion rate improved to 3.85

bookChallenge: 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 reward and initialize it with 100.
  • Use a for loop that runs from 1 to the value of customerPosition.
  • On each iteration, add 50 to the reward variable.
  • Return the final value of reward.

Example

calculateReward(1) => 100
calculateReward(2) => 150
calculateReward(15) => 800

Solution

solution.cpp

solution.cpp

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Β 4. ChapterΒ 6
single

single

some-alt