Interest practical task

Здравейте получавам wrong answer и 40 точки на една от практическите задачи. Условието е следното:
You have deposited a sum into your bank account for 3 years. The bank has announced an interest of 5% per year. Each time the interest is calculated and added to your deposit. You have to calculate the amount in your deposit for each year.

Input

  • On the only line you will receive a number (n) with the sum deposited

Output

  • You should print the amount in your deposit for each of the 3 year

  • You must print the number with two numbers after the decimal point. The rules of math for rounding appl
    Аз компилирах програмата по следния начин. Условието се изпълнява в Visual studio.

       int deposit = int.Parse(Console.ReadLine());
              decimal y1 = dep + 0.05m * deposit;
      decimal y2 = y1 + 0.05m * y1;
      decimal y3 = y2 + 0.05m * y2;
      
      Console.WriteLine(Math.Round(y1,2));
      Console.WriteLine(Math.Round(y2,2));
      Console.WriteLine(Math.Round(y3,2));
    

Програмата не показва грешки във visual studio
Благодаря предварително.

Здравей,

доколкото виждам в условието не е казано изрично, че депозита ще бъде цяло число, а ти четеш входните данни като int.

Поздрави!

1 Like

Благодаря за отговора. Аз пробвах да го направя и с decimal. “decimal deposit =…”
но това не промени нещата. Пак получих 40 точки и wrong answer

А каква е тази променлива dep ?
Изпиши си вместо dep-deposit и тествай отново.

Благодаря ти за отговора. Погледнах дали тази грешка съм я поправил . Да поправил съм я но Judge ми дава 40 точки и Wrong answer.
Помествам отново моето решение.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
static void Main()
{
decimal deposit = decimal.Parse(Console.ReadLine());
decimal y1 = deposit + 0.05m * deposit;
decimal y2 = y1 + 0.05m * y1;
decimal y3 = y2 + 0.05m * y2;
Console.WriteLine(Math.Round(y1, 2));
Console.WriteLine(Math.Round(y2, 2));
Console.WriteLine(Math.Round(y3, 2));

    // your solution here
}

}

Тук няма нужда да използваш decimal.
Ето ти едно кратко решение:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
static void Main()
{
double deposit=int.Parse(Console.ReadLine());
for(int i=1;i<=3;i++)
{
deposit=deposit*1.05;
Console.WriteLine($"{deposit:f2}");
}
}
}

Благодаря ти. Чудесно решение. В момента уча и упражнявам for, while loops и не се сетих че мога да ги приложа в този случай.