Thread: Codeing problems

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    1

    Exclamation Codeing problems

    hi,
    can any1 help me find the errors in my code. i guess they r logic because the compiler didnt catch anything. this is a program that displays the principle, interest, time, and mortgage payment onto a table on a .dat file. thanx:



    /*MP4b.cxx - Prints mortgage payment and bank heading on a table
    input: None
    output: Principle, Interest, Time, & Mortgage Payment
    author: Ryan Fehr
    */

    #include <fstream.h>
    #include <math.h>
    #include <iomanip.h>
    int main()
    {
    float P; //Principle
    float I; //Interest
    float T; //Time
    float MP; //Mortgage Payment
    ofstream out_file; //declares out_file
    out_file.open("MP4b.dat"); //opens external file MP4b.dat and
    //associates it

    I = .07;
    T = 30;

    out_file << setw(32) << "Fat_Rizzle's_Bank\n"
    << setw(46) << "Ryan_Fehr__Executive_Rizzle_CEO\n\n"
    << setw(10) << "Principle"
    << setw(12) << "Intesrest"
    << setw(8) << "Time"
    << setw(22) << "Mortgage_Payment/n";

    for(P = 50000; P<=100000; P+= 10000)
    {

    MP = (P*(I/12))/(1-pow((1/(1+(I/12))),(T*12))); //Calculates
    //Mortgage Payment

    out_file << setiosflags (ios::fixed)
    << setiosflags (ios::showpoint)
    << setprecision(2); //Sets decimal pl$
    out_file << setw(9) << P;
    out_file << setw(9) << I;
    out_file << setw(11) << T;
    out_file << setw(17) << MP;
    }

    return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109

  3. #3
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    170
    If the problem is with the file formating then look at newlines \n
    Code:
    << setw(22) << "Mortgage_Payment\n";
    ...
    ...
    out_file << setw(17) << MP << '\n';

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  3. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM