Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

How can I fix these errors I am getting in my program in C#?

$
0
0

Here's my program that I am working on:

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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            /*User will first input the information:
             * (loan amount, annual interest rate, loan period in years and number of payments made each year) 
             * needed for the calculations for the output of the loan summary*/

           
            Console.WriteLine("Please enter your loan amount");
            int _loanAmount = int.Parse(Console.ReadLine());

            Console.WriteLine("Please enter your interest rate");
            decimal _interestRate = Convert.ToDecimal(Console.ReadLine());

            Console.WriteLine("Please enter the loan period in years");
            int _loanPeriod = int.Parse(Console.ReadLine());

            Console.WriteLine("Please enter the number of payments per year");
            int _NumberofMonthlyPayments = int.Parse(Console.ReadLine());            

            // You have all the info from the user, now call the methods passing parameters
            var _amortizationTerm = AmortizationTerm(_loanPeriod, _NumberofMonthlyPayments);
            var _monthlyPayment = MonthlyPayment(_interestRate, _amortizationTerm, _loanAmount);
            var _totalInterest = TotalInterest(_loanAmount, _loanPeriod, _NumberofMonthlyPayments, _monthlyPayment);
        }

        /*The information below is needed to calculate the:
         *(the total interest, scheduled payments and number of monthly payments)
           needed for the output of the loan summary*/
        
        public static double MonthlyPayment(decimal _interestRate, double _amortizationTerm, int _loanAmount)
        {
            /*Calculate monthly payment and round to 2 decimal places*/
            var monthlyPayment = ((_interestRate / 12) / (1 - (Math.Pow((1 + (_interestRate / 12)), -(_amortizationTerm))))) * _loanAmount;
            monthlyPayment = Math.Round(monthlyPayment, 2);
            return monthlyPayment;

        }

        public double TotalInterest(int _loanAmount, int _loanPeriod, int _NumberofMonthlyPayments, double _monthlyPayment)
        {
            var _amortizationTerm = AmortizationTerm(_loanPeriod, _NumberofMonthlyPayments);
            var TotalInterest = _monthlyPayment - (_loanAmount / _amortizationTerm) * _amortizationTerm;
            Console.WriteLine("The total interest paid on loan is ${0}", TotalInterest);
            return TotalInterest;
        }


        public double AmortizationTerm(int _loanPeriod, int _NumberofMonthlyPayments)
        {
            /* Below the following equations represnts the:
             * number of payments (12) multiplied by the loan period in years (30) 
             * to calculate the scheduled and actual number of payments (360) */

            var _amortizationTerm = _loanPeriod * _NumberofMonthlyPayments;
            Console.WriteLine("The total number of monthly scheduled payments is {0}", _amortizationTerm);
            return _amortizationTerm;
        }



        }
    }

And here are the errors that I am getting:

An object reference is required for the non-static field, method, or property'ConsoleApplication2.Program.AmortizationTerm(int, int)'

An object reference is required for the non-static field, method, or property'ConsoleApplication2.Program.TotalInterest(int, int, int, double)'

Argument 1: cannot convert from 'decimal' to 'double'

Th best overloaded method match for 'System.Math.Pow(double,double)' has some invalid arguments

I don't know how to resolve these errors.


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>