help with little prog

This is a discussion on help with little prog within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <conio.h>// for getch() using namespace std; int main() { int amount; int years; int month = ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    494

    help with little prog

    Code:
    #include <iostream>
    #include <conio.h>// for getch()
    using namespace std;
    
    
    int main()
    {
    	int amount;
    	int years;
    	int month = 12;
    	float payment;
    
    
    	cout << "This program calculates your morgage loan payments per month\n";
    	cout<< "Enter the amount of $ the house costs: ";
    	cin >> amount;
    
    	cout <<"Enter the years you want to pay off the morgage: ";
    	cin >> years;
    
    
    	 payment =(amount /years) / 12;
    
    
    	cout << "You will have to pay " << payment << " per month\n";
    	cout << "Press a key to close the screen.";
    	getch(); //this waits for a user to entre any key before it closes
    
    	return 0;
    }
    so anyone can help me to make this code look better lol i got no idea if im following correct programing styles or whatever.
    aslo the prog works fine but it lacks something. there is no interest, how is interest calculated?
    When no one helps you out. Call google();

  2. #2
    wierd guy bart's Avatar
    Join Date
    Aug 2001
    Posts
    87
    Nothing looks that bad to me. look at http://geosoft.no/style.html for some style guidlines.

    the total amount of interest can be calculated through

    [original amount] * ( 1 + ( [percentage of interest] / 100 ) ^ [number of months/years/whatever] )

    but this is economics, not programming

  3. #3
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    Only thing I would suggest is at the end of a cout where you want a new line you should use "<< endl;" instead of the newline escape character.

    Also you have the variable month but you don't use it (or need it) there's always 12 months in a year, so get rid of that.

    edit: There is also a 't' in Mortgage
    Last edited by HybridM; 04-25-2004 at 03:04 PM.
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    thanks for the input. ill try and fix it

    edit: about the year is always 12 months but still shouldnt i have that there so if someone doesnt know what the 12 means he would know that its the months? or would a comment b more than enough?
    When no one helps you out. Call google();

  5. #5
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    I think it's pretty easy to work it out without anything at all. But you could put a comment there if you're worried. Don't over-comment though, cardinal sin.
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assembly amature question: prog errors
    By geek@02 in forum Tech Board
    Replies: 1
    Last Post: 10-03-2008, 01:35 PM
  2. Getting input from another prog?
    By Badman3k in forum C Programming
    Replies: 4
    Last Post: 11-11-2004, 01:58 AM
  3. an option at the end of this prog to ask if I want to run again
    By bandito9111 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2003, 01:30 PM
  4. Try my prog...
    By Commander in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 05-09-2002, 07:43 AM
  5. password prog
    By ihsir in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 01-06-2002, 05:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21