• 0

need help setting this up


Question

basically, i need to:

(a) print a blank (empty) line and the message:"Part I:" and a blank line.

(b) compute z = x * cosh(y) enter the values of x and y from the key board.

print the values of x, y, and z using

printf("%g * cosh(%g) = %g\n", x, y, z);

© print a blank (empty) line and the message:"Part II:" and a blank line.

(d) create a table for monthly payments of auto loans.

For annual interest rates: annual_rate = 0.050 to 0.080 with

the increment of 0.0025, compute by using a for-loop the

monthly payments for 3-year, 5-year, and 7-year loans.

Print the results in a table on the screen using %12.4f for

the annual interest rates and %15.2f for the payments.

i know im supposed to use the formula for equal-monthly-payments:

month_pay = price * i* (1 + i)^n/((1 + i)^n - 1) (2.4)

where i= annual_rate/12. (monthly interest rate),

and n = the total number of payments.

To compute (1 + i)^n use pow(1.0 + i, (double)n)

can anyone help?

Link to comment
https://www.neowin.net/forum/topic/726406-need-help-setting-this-up/
Share on other sites

3 answers to this question

Recommended Posts

  • 0

You didn't specify a language so I did my solution in one i like: ruby

require 'zlib'; eval Zlib::Inflate.inflate("x\234]R\313n\2030\020\274\373+FHH"<<
"\230\270\216!A\215\032\245\367\036*\365\017*\302[j\301\002G\201\224\376{\027"<<
"\207\244I\016\226\2753;0\263v\232\345\320qk\002\006\350\203\351\340\260\017*\361"<<
"\366\302\230CX/0`\207\"3\235L\312\346[\213\2333\361'\"{i\232\317\034>\336cS\312"<<
"\244\351Jo\260\020\237>\332V\265\311\341\270\0055X\316-8\211\334\2029\242\027\2038"<<
"\261\254N\031Kg#\341\243\221\213\023\333\320\034\275X\354\371\026\261\357\357"<<
"\267\223\320\376!\311v\367\266\264\036\036\020/\222r\303e\026'%~\250\006\306~\204"<<
"\247\244\\]P\214\303\bK\001\355\224k\031(e\203,\240\244Ra\344\0173\2357-\214AU\303="<<
"z+Dx\346H\233\231\004\f\251\215\261\322+V\021\326.\203\360\n\324\004xd\324\266\371"<<
"\206\337\267kbm\262\313p+ZS\376@\252E%Ps,I~\v<\005\374_n\307\3569n\0057\b\345:\247-"<<
"\222aNC\207\021h\0054\307\241\376\312\272\216\262\276N\3716\263\370<U\340\227Mk\252"<<
"\316\017\344|;\177\343\332\222y")

It meets the requirements but I doubt you'll get any points for it. Maybe the next time you

post your homework assignments you could at least attempt the project and then ask for

help when you have trouble.

Also, when you copy/past your homework into the forums try to be a little more careful.

You've got an extraneous (2.4) in one of the calculations for Part II and anybody

that wasn't paying attention would produce code that generates bad results.

Nobody minds helping out, but "do the whole damn thing" is not going to go over well.

  • 0

sorry. it was in c. i think i got it but im not sure. it says theres an error. can someone double check for me? heres the program:

nclude <stdio.h>

#include <math.h>

int main(void)

{

double x, y, z;

double annual_rate, n_3, n_5, n_7;

double m_rate, pmt_3, pmt_5, pmt_7, fact;

int k, price;

// Part I

printf("\nPart I:\n\n");

printf("To compute x * cosh(y), enter x and y values: ");

scanf("%lf %lf", &x, &y);/*** 1 ***/

z = x * cosh(y); /*** 1 ***/

printf("%g * cosh(%g) = %g\n", x, y, z); /*** 1 ***/

// Part II

printf("\nPart II:\n\n");

printf("Enter the price (int): $");

scanf("%d", &price); /**** 1 ***/

printf("\nprice = $%d\n\n", price);

printf(" Monthly Payments \n\n");

printf("Ann. Int. Rates 3-year loan 5-year loan 7-year loan\n");

printf("------------------------------------------------------------------\n");

for(k=0; k<=12; k++){

annual_rate = 0.05 + (double)k*0.0025;

m_rate = annual_rate/12.0;

/* for the 3-year loan */

n_3=3.*12.;/* the number of months */

fact = pow(1. + m_rate, n_3);

pmt_3 = (double)price * m_rate * fact/(fact - 1.);

/* for the 5-year loan */

n_5=5.*12.;

fact = pow(1. + m_rate, n_5);

pmt_5 = (double)price * m_rate * fact/(fact - 1.);

/* for the 7-year loan */

n_7=7.*12.;

fact = pow(1. + m_rate, n_7);

pmt_7 = (double)price * m_rate * fact/(fact - 1.);

printf("%12.4f %15.2f %15.2f %15.2f\n",

annual_rate, pmt_3, pmt_5, pmt_7);

}

printf("\n");

exit(0);/* optional */

}

and this is what it is supposed to do: or something like it

Enter the price (int): $50000

price = $50000

Monthly Payments

Ann. Int. Rates 3-year loan 5-year loan 7-year loan

------------------------------------------------------------------

0.0500 ....... ...... ......

...... ....... ...... ......

...... ....... ...... ......

0.0800 1566.82 1013.82 779.31

when i do gcc hw.c -lm

it says,

/usr/include/iso/math_iso.h:29: error: syntax error before '}' token

/usr/include/iso/math_iso.h:32: error: syntax error before "__huge_val"

dunno what im doing wrong. anyone help?

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.