• 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.
  • Posts

    • Sony started with 70 Euro games, Nintendo with 80 Euro games.
    • It has only been about 2 years since Microsoft raised prices from $60 to $70! I don't think it's a good idea they are doing it again so soon. Instead of raising prices, manage game development budgets better.
    • Intel's 20-core Ultra 7 processor is now available with a massive discount by Taras Buria The Intel Core Ultra 7 265K, Intel's latest 20-core desktop processor, is getting more affordable. Now, the chip is available on Amazon with a 36% discount, saving you $144, which you can spend on a higher-spec graphics card, better cooling, a bigger SSD, or some new games. If you want to build a computer with the discounted Intel Core Ultra 7 265K, you will need a motherboard with the LGA 1851 socket and 800 series chipset. The Core Ultra 7 265K has 20 cores, 8 of which are performance cores, and 12 are efficiency cores operating at lower clocks for less demanding tasks. Performance cores have the maximum clock speed of 5.4GHz, while efficiency cores peak at 4.6GHz. However, the processor is unlocked, which means you can push those clocks higher if you have enough cooling and a motherboard that supports overclocking. Speaking of cooling, the processor has a TDP of 125W. A cooler is not included in the box, so do not forget to add one to your shopping cart. The Intel Core Ultra 7 265K has 30MB of level 3 cache (L3). It works with DDR5 memory (rated for 6,400 MT/s) and has a built-in graphics at 2GHz, which is enough for image output, media consumption, and all sorts of tasks that do not require a lot of GPU power. There is also a neural processing unit with 13 TOPS, which can handle on-device AI processing. Intel Core Ultra 7 Desktop Processor 265K 5.5 GHz - $259.99 | $144 off on Amazon US This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • It's stuff like this countries like Denmark are giving up by switching to Linux. Good luck to them.
    • I think a big part of it is developers have grown themselves too big and ballooned their budgets. It's the only way to show endless growth to investors between releases. Then they make massive investments in games designed for the bottom line hoping players follow instead of designing them for the players and hoping the bottom line follow in the way smaller, indie developers do. This often causes the games to fail to hook players. Instead they need to streamline development, lower budgets and sales forecasts, actually listen to gamer feedback, realize that social media doesn't dictate real world gaming tastes and habits, and overall learn to adapt instead of regurgitating the same formulas over and over.
  • Recent Achievements

    • Week One Done
      bukro earned a badge
      Week One Done
    • One Year In
      Wulle earned a badge
      One Year In
    • One Month Later
      Wulle earned a badge
      One Month Later
    • One Month Later
      Simmo3D earned a badge
      One Month Later
    • Week One Done
      Simmo3D earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      552
    2. 2
      ATLien_0
      246
    3. 3
      +FloatingFatMan
      167
    4. 4
      Michael Scrip
      121
    5. 5
      Steven P.
      95
  • Tell a friend

    Love Neowin? Tell a friend!