How can I make this amortization library program run?

These are the instructions for this program I have to do: http://justpaste.it/lk6s . It has two source files and one resource file. I think I am close to getting this code to run, but I just can't figure this out right now. I woke up with food poisoning this morning and I can barely stay awake or keep my eyes open, but I need to get this to run and turn it in.

I get this error: http://i.imgur.com/D8QQyE4.png when I try to use this pow function.
If I temporarily delete the pow function and try to run the program, I get this error: http://i.imgur.com/rwt61cy.png, because the variable monthPaid is uninitialized. I sort of lost track of my math & variables, and I'm at a loss as to how to make this thing work out.
Sorry if these questions seem stupid, I'm really new to C++ and this is just an assignment I have to do.

This is the code I have written:

Amort.h:
1
2
3
 double getPaymentAmount(int months, double principal, double interest);
double getPrincipalAmount(int months, double payment, double interest);
int getNumberOfMonths(double payment, double principal, double interest);


Amort.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>
 
using namespace std;
 
void calculationAmort(float P, float interestYear, int ny);
void printSch(int i, float P, float monthPaid, float interestPaid, float principalPaid, float newBalance);
 
double RoundedPct(double interestMonth)
{
 double Eighths[] = {0.0, .125, .25, .375, .5, .625, .75, .875, 1.0};
 int wholePct;
 double fracPct;
 int i;
 
 wholePct = (int)(100.0 * interestMonth);
 fracPct = 100.0 * interestMonth - wholePct;
 
 for (i = 0; i < 8; i++)  {
 if (Eighths[i] <= fracPct && fracPct <= Eighths[i + 1])
 {
 if (fracPct - Eighths[i] <= Eighths[i + 1] - fracPct)
 fracPct = Eighths[i];
 else fracPct = Eighths[i + 1];
 break;
 }
 }
 
 interestMonth = (wholePct + fracPct)/100.0;
 return interestMonth;
}
 
void calculationAmort(float P, float interestYear, int ny)
 
{
float newBalance;
float interestMonth = (interestYear/1200);
float interestPaid, principalPaid, monthPaid;
 
 
int i;
int nm=ny*12;
 
    for(i=1;i<nm;i++)
      {
             
       
        interestPaid = P*interestMonth;//interest paid
        principalPaid = monthPaid-interestPaid; //princial paid
        newBalance = P-principalPaid; //new balance
                 
        printSch(i,P,monthPaid,interestPaid,principalPaid,newBalance); //print amortization table
        P = newBalance;  //update old balance    
             
        }
}
     
void printSch(int i, float P, float monthPaid, float interestPaid, float principalPaid, float newBalance)
{
     
   cout << std::setprecision(5) << fixed;
   cout<<i<<"\t"<<P<<"\t\t"<<monthPaid<<"\t\t"<<interestPaid<<"\t\t"<<principalPaid<<"\t\t"<<newBalance<<"\n";
     
 }
 
 
 
double getPaymentAmount(int months, double principal, double interest)
{
        double Payment;
        return Payment = (pow (1 + interest, months))/(pow (1 + interest, months-1)) * principal * interest;
}
 
double getPrincipalAmount(int months, double payment, double interest)
{
        double Principal;
        return Principal = (pow (1 + interest, months-1))/(pow (interest * (1 + interest, months))) * payment;
}
 
int getNumberOfMonths(double payment, double principal, double interest)
{
        int Months;
        return Months = (log(payment)-log(payment-(principal*interest)))/log(1+interest);
}


Main.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
#include "Amort.h"
 
 
char menu;
double principal, payment;
double annualRate, roundedRate;
int months;
 
int main(void)
{
        printf("1. Calculate (P)ayment size ");
        printf("2. Calculate (L)oan size ");
        printf("3. Calculate (N)umber of payments ");
        printf("4. (Q)uit ");
        printf("Select a menu");
        scanf_s("%c", &menu, 1);
 
       
        switch(menu)
        {
                case '1':
                case 'P':
                case 'p':
                        printf("Enter the annual interest rate: ");
                        scanf_s("%lf", &annualRate, 1);
                        printf("Enter the size of the loan: ");
                        scanf_s("%lf", &principal, 1);
                        printf("Enter the number of payments: ");
                        scanf_s("%d", &months, 1);
                        printf("Payment is %.21f \n", getPaymentAmount(months, principal, roundedRate));
                        break;
 
                case '2':
                case 'L':
                case 'l':
                        printf("Enter the annual interest rate: ");
                        scanf_s("%lf", &annualRate, 1);
                        printf("Enter size of each payment: ");
                        scanf_s("%lf", &payment, 1);
                        printf("Enter the number of payments: ");
                        scanf_s("%d", &months, 1);
                        printf("Principal is %.21f \n" , getPrincipalAmount(months, payment, roundedRate));
                        break;
 
                case '3':
                case 'N':
                case 'n':
                        printf("Enter the annual interest rate: ");
                        scanf_s("%lf", &annualRate, 1);
                        printf("Enter size of the loan: ");
                        scanf_s("%lf", &payment, 1);
                        printf("Enter the size of each payment: ");
                        scanf_s("%d", &months, 1);
                        printf("Number of month is %.21f \n" , getNumberOfMonths(months, payment, roundedRate));
                        break;
 
                case '4':
                case 'Q':
                case 'q':
                        fclose;
        }
 
       
 
}


pow(...) requires two pramameters (base and exponent):

http://www.cplusplus.com/reference/cmath/pow/?kw=pow

You provided just one.
Topic archived. No new replies allowed.