A
AG
Hello,
This is my first post to this group, and on top of that I am a
beginner. So please direct me to another group if this post seems out
of place....
I have recently written a program which calculates loan
amortization schedules, writes the data to a text file, and then upon
user prompt, the program will display the created file and print the
file. Until this morning, everything worked fine, and then I started
messing around with the scanf() function. Now none of my system
commands are working. I have rewritten the program to it's original
form (as much as I can remember), but none of my system commands work.
Everything else works. I have included the file here. If someone
could explain why the system commands won't work, I would appreciate
it. The compiler I am using isn lccwin32.
thanks,
AG
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
double
amount,down,payment,pay_m,taxes,tax_m,insurance,ins_m,extra,borrowed,num,den,years,months,T;
float interest,int_m;
double balance[1000], total_int[1000],inputs[6];
unsigned int n,count=1,k,flag;
char name[];
void prog_header(void);
void print_results(void);
void disp_results(void);
void print_file(void);
int selection(void);
FILE *fp;
double get_values(double arg[]);
void main(void)
{
system("CLS");
prog_header();
n=0;
k=0;
while(count==1)
{
printf("\n\n\nEnter cost of house: $");
scanf(" %lf",&amount);
printf("Enter downpayment: $");
scanf(" %lf",&down);
printf("Enter annual interest rate (as percent not decimal): ");
scanf(" %f",&interest);
printf("Enter life of loan (years): " );
scanf(" %lf",&years);
printf("Enter annual taxes (0 if not known): $" );
scanf(" %lf",&taxes);
printf("Enter annual insurance (0 if not known): $" );
scanf(" %lf",&insurance);
int_m=(interest)/1200;
months=years*12;
tax_m=taxes/12;
ins_m=insurance/12;
borrowed=amount-down;
payment=(int_m*borrowed)/(1-pow((1+int_m),-months));
pay_m=payment+tax_m+ins_m;
T=0;
for(n=1;n<=months;n++)
{
balance[0]=amount-down;
balance[n]=(1+int_m)*balance[n-1]-pay_m+tax_m+ins_m-extra;
total_int[n]=balance[n-1]*int_m;
T=T+total_int[n];
}
print_results();
printf("\n\n\n\n\n");
count=selection();
if(count==1)
{
system("CLS");
for(k=1;k<100000;k++)
{}
}
if(count==2)
{
disp_results();
printf("\n\n\t Enter 1 to continue...");
scanf("%i",&flag);
flag=system("CLS");
count=1;
}
if (count==3)
{
print_file();
}
}
}
int selection(void)
{
try_again:
printf(" \n What do you want to do?");
printf("\n\t [1] Enter another loan");
printf("\n\t [2] See file details and then enter another loan");
printf("\n\t [3] Print file and quit program\n");
printf("\n\t......");
scanf("%i",&count);
if(count>3 | count<1)
goto try_again;
return count;
}
void prog_header(void)
{
printf("\n\n * * * WELCOME TO THE LOAN CALCULATOR * * * \n\n");
printf("\nThis program will do the following....");
printf("\n\n [1] Determine how large your monthly loan payments will
be");
printf("\n [2] Calculate amount of interest paid during the life of
the loan.");
printf("\n [3] Create an amortization schedule for the life of the
loan.");
printf("\n\n The output file will be in \"loanfiles\" folder on
the c drive");
printf("\n\n The output file will be called
\"payment_schedule\"");
}
void print_results(void)
{
printf("\n\n\n RESULTS \n");
printf(" --------------------------------------- ");
printf("\n\t Cost of house: $%0.2f",amount);
printf("\n\t Down payment: $%0.2f",down);
printf("\n\t Amount borrowed: $%0.2f",borrowed);
printf("\n\t Interest rate: %1.2f%%",interest);
printf("\n\t Monthly payment: $%.2f",pay_m);
printf("\n\t Total interest paid: $%.2f",T);
}
void disp_results(void)
{
for(n=0;n<=months;n++)
{
if(n%12==0)
{ k++;
printf("\n Year %d Balance %.2f",k-1,balance[n]);
}
}
}
void print_file(void)
{
flag=system("mkdir c:\\loanfiles");
fp=fopen("c:\\loanfiles\\payment_schedule.txt","w");
fprintf(fp,"\n********************************************\n");
fprintf(fp,"\n Loan Amortization Schedule\n");
fprintf(fp,"\n********************************************\n\n");
fprintf(fp, "Cost of house: $%.2f\n",amount);
fprintf(fp, "Down payment: $%.2f\n",down);
fprintf(fp, "Loan Amount: $%.2f\n",borrowed);
fprintf(fp, "Loan Duration: %.0f years\n",years);
fprintf(fp, "Interest rate: %1.3f%%\n",interest);
fprintf(fp, "Monthly payment: $%.2f\n",pay_m);
fprintf(fp, "Total interest paid: $%.2f\n\n\n",T);
fprintf(fp, " Year Balance\n");
fprintf(fp,"-------------------------------\n");
k=0;
for(n=0;n<=months;n++)
{
if(n%12==0)
{ k++;
fprintf(fp," %5d %15.2f\n", k-1,balance[n]);
}
}
flag=fclose(fp);
flag=system("c:\\WINDOWS\\system32\\notepad.exe
c:\\loanfiles\\payment_schedule.txt");
flag=system("print c:\\loanfiles\\payment_schedule.txt");
flag=system("exit");
}
This is my first post to this group, and on top of that I am a
beginner. So please direct me to another group if this post seems out
of place....
I have recently written a program which calculates loan
amortization schedules, writes the data to a text file, and then upon
user prompt, the program will display the created file and print the
file. Until this morning, everything worked fine, and then I started
messing around with the scanf() function. Now none of my system
commands are working. I have rewritten the program to it's original
form (as much as I can remember), but none of my system commands work.
Everything else works. I have included the file here. If someone
could explain why the system commands won't work, I would appreciate
it. The compiler I am using isn lccwin32.
thanks,
AG
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
double
amount,down,payment,pay_m,taxes,tax_m,insurance,ins_m,extra,borrowed,num,den,years,months,T;
float interest,int_m;
double balance[1000], total_int[1000],inputs[6];
unsigned int n,count=1,k,flag;
char name[];
void prog_header(void);
void print_results(void);
void disp_results(void);
void print_file(void);
int selection(void);
FILE *fp;
double get_values(double arg[]);
void main(void)
{
system("CLS");
prog_header();
n=0;
k=0;
while(count==1)
{
printf("\n\n\nEnter cost of house: $");
scanf(" %lf",&amount);
printf("Enter downpayment: $");
scanf(" %lf",&down);
printf("Enter annual interest rate (as percent not decimal): ");
scanf(" %f",&interest);
printf("Enter life of loan (years): " );
scanf(" %lf",&years);
printf("Enter annual taxes (0 if not known): $" );
scanf(" %lf",&taxes);
printf("Enter annual insurance (0 if not known): $" );
scanf(" %lf",&insurance);
int_m=(interest)/1200;
months=years*12;
tax_m=taxes/12;
ins_m=insurance/12;
borrowed=amount-down;
payment=(int_m*borrowed)/(1-pow((1+int_m),-months));
pay_m=payment+tax_m+ins_m;
T=0;
for(n=1;n<=months;n++)
{
balance[0]=amount-down;
balance[n]=(1+int_m)*balance[n-1]-pay_m+tax_m+ins_m-extra;
total_int[n]=balance[n-1]*int_m;
T=T+total_int[n];
}
print_results();
printf("\n\n\n\n\n");
count=selection();
if(count==1)
{
system("CLS");
for(k=1;k<100000;k++)
{}
}
if(count==2)
{
disp_results();
printf("\n\n\t Enter 1 to continue...");
scanf("%i",&flag);
flag=system("CLS");
count=1;
}
if (count==3)
{
print_file();
}
}
}
int selection(void)
{
try_again:
printf(" \n What do you want to do?");
printf("\n\t [1] Enter another loan");
printf("\n\t [2] See file details and then enter another loan");
printf("\n\t [3] Print file and quit program\n");
printf("\n\t......");
scanf("%i",&count);
if(count>3 | count<1)
goto try_again;
return count;
}
void prog_header(void)
{
printf("\n\n * * * WELCOME TO THE LOAN CALCULATOR * * * \n\n");
printf("\nThis program will do the following....");
printf("\n\n [1] Determine how large your monthly loan payments will
be");
printf("\n [2] Calculate amount of interest paid during the life of
the loan.");
printf("\n [3] Create an amortization schedule for the life of the
loan.");
printf("\n\n The output file will be in \"loanfiles\" folder on
the c drive");
printf("\n\n The output file will be called
\"payment_schedule\"");
}
void print_results(void)
{
printf("\n\n\n RESULTS \n");
printf(" --------------------------------------- ");
printf("\n\t Cost of house: $%0.2f",amount);
printf("\n\t Down payment: $%0.2f",down);
printf("\n\t Amount borrowed: $%0.2f",borrowed);
printf("\n\t Interest rate: %1.2f%%",interest);
printf("\n\t Monthly payment: $%.2f",pay_m);
printf("\n\t Total interest paid: $%.2f",T);
}
void disp_results(void)
{
for(n=0;n<=months;n++)
{
if(n%12==0)
{ k++;
printf("\n Year %d Balance %.2f",k-1,balance[n]);
}
}
}
void print_file(void)
{
flag=system("mkdir c:\\loanfiles");
fp=fopen("c:\\loanfiles\\payment_schedule.txt","w");
fprintf(fp,"\n********************************************\n");
fprintf(fp,"\n Loan Amortization Schedule\n");
fprintf(fp,"\n********************************************\n\n");
fprintf(fp, "Cost of house: $%.2f\n",amount);
fprintf(fp, "Down payment: $%.2f\n",down);
fprintf(fp, "Loan Amount: $%.2f\n",borrowed);
fprintf(fp, "Loan Duration: %.0f years\n",years);
fprintf(fp, "Interest rate: %1.3f%%\n",interest);
fprintf(fp, "Monthly payment: $%.2f\n",pay_m);
fprintf(fp, "Total interest paid: $%.2f\n\n\n",T);
fprintf(fp, " Year Balance\n");
fprintf(fp,"-------------------------------\n");
k=0;
for(n=0;n<=months;n++)
{
if(n%12==0)
{ k++;
fprintf(fp," %5d %15.2f\n", k-1,balance[n]);
}
}
flag=fclose(fp);
flag=system("c:\\WINDOWS\\system32\\notepad.exe
c:\\loanfiles\\payment_schedule.txt");
flag=system("print c:\\loanfiles\\payment_schedule.txt");
flag=system("exit");
}