943,739 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 4692
  • C RSS
Jul 23rd, 2004
0

Output in the text file

Expand Post »
Hello,
I'm just a beginner (student). Now still undergo C programming class to upgrade my knowledge in C. I was asked to complete a simple program to get the output of C program in the text file as shown below. This program is to help user to consider a range of interest rates for bank loan over 10,20,30 years. Prior to get this output the user is asked to enter the amount loan and a minimum & maximum interest rate. The output has to be in the form of text file as below.

Eg. Loan Amount : xxxxxx

Interest Rate Duration Monthly Payment Total Payment
xxxxx xxxx xxxxxxxx xxxxxxxx

I'm thinking to use the following formula for calculating the monthly payment & transfer the result to "Monthly payment column" above. However, I have no idea what to do first & how to go about to get this result printed in the text file. Can I use this math equation---> payment = i*p/1-pow(1+i,-n).

Anyone has a similar program that I can use or study in order for me to get start. Your assistance is highly appreciated.

Rgds,
GKS

( Note : Formula for mthly payment = ip/1-(1+i)-n ).
Reputation Points: 10
Solved Threads: 0
Newbie Poster
KSGuan is offline Offline
5 posts
since Jul 2004
Jul 24th, 2004
0

Re: Output in the text file

Well, printf() will print to 'standard out' which can be directed to a text file.

fprintf() is what you want, though. fopen() opens the file, fprintf() writes text to it, and fclose() will close it.

If you look up those routines you'll have all that you need.

Good luck!
Reputation Points: 36
Solved Threads: 11
Posting Pro in Training
Chainsaw is offline Offline
436 posts
since Jun 2004
Jul 24th, 2004
0

Re: Output in the text file

If you want a tut on fstream look in the tutorial fourm
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004
Jul 24th, 2004
0

Re: Output in the text file

Hi Chainsaw,

Thanks for your reply. I'll try to it again.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
KSGuan is offline Offline
5 posts
since Jul 2004
Jul 25th, 2010
0
Re: Output in the text file
if the out put is
x
xxx
xxxxx
xxxxxxx
Reputation Points: 10
Solved Threads: 0
Newbie Poster
joemil is offline Offline
4 posts
since Jul 2010
Jul 25th, 2010
0

c pointers

if the out put is
x
xxx
xxxxx
xxxxxxx[/QUOTE]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
joemil is offline Offline
4 posts
since Jul 2010
Jul 26th, 2010
0
Re: Output in the text file
The fastest way to do this, is to:

1) Get your basic FLOW and calculations of the program, working correctly. At first, just display it on the screen - it's faster, and so easy to go back AFTER you have the basics right, and change the printf() statements, to fprintf(), and just add the file pointer.

2) Check your equation out on Google - I'm sure a basic equation like that is all over. Whatever numbers you get at first, check it and make sure it's right, before you do much else.

3) Post up your skeleton program, minus the final details, if you get stuck and need some help. Check each function as you code it, for syntax and other errors, before going to the next function.

Once you get the basics working, the details just fall into place nicely.
Reputation Points: 416
Solved Threads: 181
Nearly a Posting Virtuoso
Adak is offline Offline
1,463 posts
since Jun 2008
Jul 26th, 2010
0
Re: Output in the text file
Hi ,
Formula is your chioce, you have to careful with files.

1. Made your calculations first and store them in strings, at last you can write your output in files.
2. if you close your file once and open again means,your file pointer is in beginig of your file, you have to be careful with that.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
codewriter_IND is offline Offline
1 posts
since Jul 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: C program help!!
Next Thread in C Forum Timeline: Word Wrapping with Win32 EDIT control





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC