Easy 0 solved 0% acceptance

Simple Interest

Find the total amount after simple interest.

What you'll learn

  • Turn a word problem into a formula
  • Work with percentages
  • Return a decimal amount

Problem

Money in a savings account earns simple interest: each year adds rate percent of the original amount principal. Compute the total balance after years years.

Implement simple_interest_total(principal, rate, years).

Input

principal: The starting amount. rate: The yearly interest rate in percent. years: The number of whole years.

Output

Return principal + principal × rate / 100 × years.

Constraints

0 ≤ principal ≤ 1,000,000; 0 ≤ rate ≤ 100; 0 ≤ years ≤ 100

Examples

Example 1
Input:
rate = 5.0
years = 2
principal = 1000.0

Expected output:
expected = 1100.0
Input:
double rate = 5.0;
long long years = 2;
double principal = 1000.0;

Expected output:
double expected = 1100.0;
Input:
double rate = 5.0;
long years = 2;
double principal = 1000.0;

Expected output:
double expected = 1100.0;

Explanation

Each year earns 1000 × 5% = 50, so two years add 100: 1000 + 100 = 1100.

Example 2
Input:
rate = 0.0
years = 10
principal = 250.0

Expected output:
expected = 250.0
Input:
double rate = 0.0;
long long years = 10;
double principal = 250.0;

Expected output:
double expected = 250.0;
Input:
double rate = 0.0;
long years = 10;
double principal = 250.0;

Expected output:
double expected = 250.0;

Explanation

With a 0% rate nothing is added, so the balance stays 250.

How to approach it

Try on your own first, then open one hint at a time.

Hint 1

Simple interest uses the original principal every year, not the growing balance.

Hint 2

Compute the yearly interest once, then multiply by the number of years.

Hint 3

Make sure the final amount includes the starting principal as well as the accumulated interest.

Expected complexity

O(1) time, O(1) extra space

References

This challenge is adapted for CodeUtility. Follow the statement and constraints above.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.