Unknown Error

I can't seem to understand why my program isn't working, could someone look over it? I'm not getting any error messages when I run it so I don't know what to look for. Any help would be appreciated.

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
  #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
	double initialLoan = 0.0;
	double aprAmount = 0.0;
	double monthlyPayment = 0.0;
	int i = 0;
	double AmountOwned[] = { 0.0 };
	double AmountPaid[] = { 0.0 };
	double counter = 0.0;
	double todaysPayment = 0.0;
	double time[] = { 0.0 };
	double rate = 0.0;
	const double e = 2.71828182845905;

	printf("Enter in the total loan amount:");
	scanf("%lf", &initialLoan);
	printf("Enter in the Annual Percentage Rate (APR) % :");
	scanf("%lf", &aprAmount);
	printf("Enter in the monthly payment amount:");
	scanf("%lf", &monthlyPayment);

	AmountOwned[0] = initialLoan;
	AmountPaid[0] = 0.0;
	counter = 1; 
	rate = aprAmount / 100 * 365.242;

	for (i = 1; AmountOwned[i] <= 0; ++i){
		if (counter == 30){
			todaysPayment = monthlyPayment;
			counter = 1;
		}
		else {
			todaysPayment = 0;
			counter = counter + 1;
		}
		time[i] = i / 365.242;
		AmountOwned[i] = (AmountOwned[i - 1] * pow(e, rate)) - todaysPayment;
		AmountPaid[i] = AmountPaid[i - 1] + todaysPayment;
	}

	printf("Total loan amount = %lf", initialLoan);
	printf("Annual Percentage Rate (APR) is %%lf", aprAmount);
	printf("Monthly payment amount of $%lf.", monthlyPayment);
	printf("After %lf years: you will owe $%lf : The total payout is $%lf.", time[i], AmountOwned, AmountPaid);

	return 0;
}
Last edited on
Is your program:
1) Not compiles
    * Is other code compiles correctly, i. e. is your compiler configured properly?
    * If it is, give us error message and corresponding code part.
2) Not running
    * Are you sure that it is not a problem with automatically closing console?
    * How do you run it?
    * Is there any error messages?
3) Gives an error when run
    * Is it system error message or error reported in console?
    * Give us error message and input which leads to error.
4) Not giving correct results
    * Tell what you entered, what you expected, and what you got.
    * Are you sure that results you expected are correct?
The program compiles but, the g.ex stops working when it is suppose to print out the values. When I run the debugger this is the message I get: Unhandled exception at 0x00BC1650 in g.exe: 0xC0000005: Access violation reading location 0x19B6C050.

It points to line 42.
Both AmountOwned and AmountPaid contains only one value. So access to values at AmountOwned[1, AmountPaid[1] is illegal. You got lucky with AmountOwned and your program did not crash as soon as line 31, but illegal access to AmountPaid leads to crash.
Last edited on
Oh so how do I fix that?
Rewrite statements to not use arrays at all.
Then things is that I have to use arrays.
So use 1 size array instead of one variable.
Or make sure that arrays are always large enough to fit everything.
After changing the array size, I got this error:

Run-Time Check Failure #2 - Stack around the variable 'AmountOwned' was corrupted.
The only part I changed was this:

1
2
3
4
5
6
7
8
9
10
11
12
int main(void){
	double initialLoan = 0.0;
	double aprAmount = 0.0;
	double monthlyPayment = 0.0;
	int i = 1;
	int AmountOwned[12600];
	int AmountPaid[12600];
	double counter = 0.0;
	double todaysPayment = 0.0;
	int time[12600];
	double rate = 0.0;
	const double e = 2.71828182845905;
I have figured out the problem, thanks for the help!
Topic archived. No new replies allowed.