Torna alle sfide
Facile 0 risolte 0% di accettazione

Simple Interest

Find the total amount after simple interest.

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.

Vincoli

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

Esempi

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

Output atteso:
expected = 1100.0
Input:
double rate = 5.0;
long long years = 2;
double principal = 1000.0;

Output atteso:
double expected = 1100.0;
Input:
double rate = 5.0;
long years = 2;
double principal = 1000.0;

Output atteso:
double expected = 1100.0;

Spiegazione

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

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

Output atteso:
expected = 250.0
Input:
double rate = 0.0;
long long years = 10;
double principal = 250.0;

Output atteso:
double expected = 250.0;
Input:
double rate = 0.0;
long years = 10;
double principal = 250.0;

Output atteso:
double expected = 250.0;

Spiegazione

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

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.