0

Problem definition: design a class BankAccount (accountno, name). Inherit this class in FixedDeposit class which has data members like principal amount (P), rate of interest (R), no. of years (N).

Allow users to input P, R, N and calculate Due Amount (A) and interest (I).

Formulas

A = P(1 + R / 100) ^ N    and   I = A - P

My code:

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

namespace prac_18
{
    public class BankAccount
    {
        int accno;
        string name;
    }

    public class FixedDeposit : BankAccount
    {
        float pamt;
        float roi;
        int years;

        public  void getdata(float p,float r,int y)
        {
            pamt = p;
            roi = r;
            years = y;
        }

        public float calc_due()
        {
             float amt = 0;
             amt = pamt * (1 + roi / 100)^years;   // Here I get the error
             return amt;
        }

        public float calc_intrest()
        {
             float  intrest = 0;
             intrest = calc_due() - pamt;
             return intrest;
        }
    }
}
Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
coc champ
  • 69
  • 2
  • 9

1 Answers1

1

In C# the ^ operator is Exclusive OR - so cannot be used with float & int.

But it looks like you want to use it to raise a value by a power, so you want to use Math.Pow

 amt = pamt * Math.Pow((1 + roi / 100), years); 
PaulF
  • 6,673
  • 2
  • 18
  • 29