#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double calcdown (double n1, double n2);
double calcfinanced (double f1,double f2);
double calcmonthly (double y1);
double in (double g1,double g2);
void write3val (double h1, double h2, double h3, double h4, double h5, double h6, double h7, double h8);
main()
{
int ans, id;
double perin, downpay, monthly, perdown,interate, finan, hou;
printf ("Enter 1 to run program; enter any other key to stop. Key = ");
scanf ("%d", &ans);
while (ans == 1)
{
printf ("\nId? ");
scanf ("%d", &id); /*if %d doens't work try %.2f*/
printf ("\nPrice of the house = "); /*remember to check the price of the house 'n' percent interest*/
scanf ("%d", &hou);
printf ("\nChoose current interest rate: 6.0, 7.0, 8.0, 9.0, 10.0, 10.5, 11.0. =% "); /* if this % fails use escape sequence*/
scanf ("%d", &perin);
while((perin < 6) || (perin > 11))
{
printf ("You typed an invalid value. Choose current interest rate: 6.0, 7.0, 8.0, 9.0, 10.0, 10.5, 11.0. =% ");
scanf ("%d", &perin); /* remember to change here if %d doesn't work*/
}
printf ("\nPercent as down payment = % ");
scanf ("%d", &perdown);
downpay = calcdown (perdown, hou);
finan = calcfinanced (hou, downpay);
monthly = calcmonthly (perin); /* mark */
interate = in (monthly, hou);
write3val (downpay, finan, monthly, interate, id, hou, perin, perdown);
printf ("\n\nId = %d", id);
printf ("\nHouse price = %d", hou);
printf ("\nInterest rate = %d", perin);
printf ("\nPercent downpayment = %d", perdown);
printf ("\n\nDown Payment = %d", downpay);
printf ("\nAmount Financed = %d", finan);
printf ("\nMonthly pay = %d", monthly);
printf ("\nTotal Interest = %d", interate);
printf ("\n\nEnter 1 to run program; enter any other key to stop. Key = ");
scanf ("%d", &ans);
}
}
double calcdown (double n1, double n2)
{
double p;
p = (n1 *.01) * n2;
return (p);
}
double calcfinanced (double f1,double f2)
{
double h;
h = f1 - f2;
return (h);
}
double calcmonthly (double y1)
{
double y2;
if (y1 == 6.00)
{
y2 = y1 * (6.00 * .001);
}
else if (y1 == 7.00)
{
y2 = y1 * 6.66 * .001;
}
else if (y1 == 8.00)
{
y2 = y1 * 7.34 * .001;
}
else if (y1 == 9.00)
{
y2 = y1 * 8.05 * .001;
}
else if (y1 == 10.00)
{
y2 = y1 * 8.78 * .001;
}
else if (y1 == 10.50)
{
y2 = y1 * 9.15 * .001;
}
else if (y1 == 11.00)
{
y2 = y1 * 9.52 * .001;
}
return (y2);
}
void write3val(double h1, double h2, double h3, double h4, double h5, double h6, double h7, double h8)
{
FILE *output;
output = fopen ("C:/homeloan.txt", "w");
fprintf (output,"\n\nId = %d", h5);
fprintf (output,"\nHouse price = %d", h6);
fprintf (output,"\nInterest rate = %d", h7);
fprintf (output,"\nPercent downpayment = %d", h8);
fprintf (output,"\nDown Payment = %.d", h1);
fprintf (output,"\nAmount Financed = %.d", h2);
fprintf (output,"\nMonthly pay = %.d", h3);
fprintf (output,"\n\nTotal Interest = %.d", h4); /* remember to put fclose somewhere*/
}
double in (double g1,double g2)
{
double t;
t = (g1 * 12 * 30) - g2;
return (t);
}
This is a program that calculates down payment, amount financed, monthly pay, and total interest for a home loan with functions that calculate for each and and function that does the printing. Problem here is when I called the function void write3val from main the a while loop it doesn't copy the calculations to the output file. I tried puting the file in the parameter of write 3 val; but then when I call it while running the program I get an error that the function calls more than 8 arguments, which is the extra file I put in the parameter. Another problem is that when I run the program it gives me 0 for downpayment, 1000 for amount financed, 0 for monthly pay, and 1000 for total interest; where 1000 came from my input of the price of the house. I variated the calculations but still got problems I check whether I got my functions right also and they seemed alright but still got problems with my calculations. Finally the last problem I checking my interest rate; I'm sure that "while((perin < 6) || (perin > 11))" would do the trick check if the user entered the wrong value that the user would be promted to enter the given values again but it didn't work. Your help is greatly appreciated, Greatly!
#include <stdlib.h>
#include <math.h>
double calcdown (double n1, double n2);
double calcfinanced (double f1,double f2);
double calcmonthly (double y1);
double in (double g1,double g2);
void write3val (double h1, double h2, double h3, double h4, double h5, double h6, double h7, double h8);
main()
{
int ans, id;
double perin, downpay, monthly, perdown,interate, finan, hou;
printf ("Enter 1 to run program; enter any other key to stop. Key = ");
scanf ("%d", &ans);
while (ans == 1)
{
printf ("\nId? ");
scanf ("%d", &id); /*if %d doens't work try %.2f*/
printf ("\nPrice of the house = "); /*remember to check the price of the house 'n' percent interest*/
scanf ("%d", &hou);
printf ("\nChoose current interest rate: 6.0, 7.0, 8.0, 9.0, 10.0, 10.5, 11.0. =% "); /* if this % fails use escape sequence*/
scanf ("%d", &perin);
while((perin < 6) || (perin > 11))
{
printf ("You typed an invalid value. Choose current interest rate: 6.0, 7.0, 8.0, 9.0, 10.0, 10.5, 11.0. =% ");
scanf ("%d", &perin); /* remember to change here if %d doesn't work*/
}
printf ("\nPercent as down payment = % ");
scanf ("%d", &perdown);
downpay = calcdown (perdown, hou);
finan = calcfinanced (hou, downpay);
monthly = calcmonthly (perin); /* mark */
interate = in (monthly, hou);
write3val (downpay, finan, monthly, interate, id, hou, perin, perdown);
printf ("\n\nId = %d", id);
printf ("\nHouse price = %d", hou);
printf ("\nInterest rate = %d", perin);
printf ("\nPercent downpayment = %d", perdown);
printf ("\n\nDown Payment = %d", downpay);
printf ("\nAmount Financed = %d", finan);
printf ("\nMonthly pay = %d", monthly);
printf ("\nTotal Interest = %d", interate);
printf ("\n\nEnter 1 to run program; enter any other key to stop. Key = ");
scanf ("%d", &ans);
}
}
double calcdown (double n1, double n2)
{
double p;
p = (n1 *.01) * n2;
return (p);
}
double calcfinanced (double f1,double f2)
{
double h;
h = f1 - f2;
return (h);
}
double calcmonthly (double y1)
{
double y2;
if (y1 == 6.00)
{
y2 = y1 * (6.00 * .001);
}
else if (y1 == 7.00)
{
y2 = y1 * 6.66 * .001;
}
else if (y1 == 8.00)
{
y2 = y1 * 7.34 * .001;
}
else if (y1 == 9.00)
{
y2 = y1 * 8.05 * .001;
}
else if (y1 == 10.00)
{
y2 = y1 * 8.78 * .001;
}
else if (y1 == 10.50)
{
y2 = y1 * 9.15 * .001;
}
else if (y1 == 11.00)
{
y2 = y1 * 9.52 * .001;
}
return (y2);
}
void write3val(double h1, double h2, double h3, double h4, double h5, double h6, double h7, double h8)
{
FILE *output;
output = fopen ("C:/homeloan.txt", "w");
fprintf (output,"\n\nId = %d", h5);
fprintf (output,"\nHouse price = %d", h6);
fprintf (output,"\nInterest rate = %d", h7);
fprintf (output,"\nPercent downpayment = %d", h8);
fprintf (output,"\nDown Payment = %.d", h1);
fprintf (output,"\nAmount Financed = %.d", h2);
fprintf (output,"\nMonthly pay = %.d", h3);
fprintf (output,"\n\nTotal Interest = %.d", h4); /* remember to put fclose somewhere*/
}
double in (double g1,double g2)
{
double t;
t = (g1 * 12 * 30) - g2;
return (t);
}
This is a program that calculates down payment, amount financed, monthly pay, and total interest for a home loan with functions that calculate for each and and function that does the printing. Problem here is when I called the function void write3val from main the a while loop it doesn't copy the calculations to the output file. I tried puting the file in the parameter of write 3 val; but then when I call it while running the program I get an error that the function calls more than 8 arguments, which is the extra file I put in the parameter. Another problem is that when I run the program it gives me 0 for downpayment, 1000 for amount financed, 0 for monthly pay, and 1000 for total interest; where 1000 came from my input of the price of the house. I variated the calculations but still got problems I check whether I got my functions right also and they seemed alright but still got problems with my calculations. Finally the last problem I checking my interest rate; I'm sure that "while((perin < 6) || (perin > 11))" would do the trick check if the user entered the wrong value that the user would be promted to enter the given values again but it didn't work. Your help is greatly appreciated, Greatly!