-
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?
-
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
-
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
-
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?
-
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. :)