Welcome! |
|
|
|
|
Site Forum |
|
|
|
|
|
Topic: Interest calculator
|

|
| Interest calculator |
| << Prev Topic | Next Topic >> |
| mikehauncho |
| Posted: 21-November-2007 at 11:21pm | IP Logged
|
|
|
Newbie

Group: Newbie
Joined: 10-November-2007 Location: United States Posts: 8
|
heres some source for a interest calcalator, i would like to hear sugestions if you got em.
#include <cstdlib> #include <iostream> #include <string> using namespace std;
int main(int argc, char *argv[]) { float x; int u; int y = 0; string d; string t = "no"; int p; do { cout << "How many dollars would you like to calculate?" << endl; cin >> x; cout << "How many years would you like to calculate?" << endl; cin >> u; cout << "How much interest per year would you like?" << endl; cin >> p; while (y<u) { y= y + 1; x= x*(p*0.01) + x; } cout << "After " << u << " years, you would have " << x << " dollars in the bank"; cout << " calculated at a " << p << "% interest rate"<< endl; cout << endl << "Would you like to calculate another sum of money?" << endl; cin >> d; } while (d != t); return EXIT_SUCCESS; }
|
Online Status: Offline
|
|
| |
| DutchDude |
| Posted: 23-November-2007 at 5:51pm | IP Logged
|
|
|
Super Dedicated Groupie

Group: Super Dedicated Groupie
Joined: 02-April-2007 Location: Netherlands Posts: 71
|
Nice idea, but some small ideas.
Use a double for x, maybe people need bigger numbers, think of companies!
in fact, don't use x, give it a real name, call it Dollars, or AmountOfMoneyPeopleSayTheyHave, but the last one is stupid, legal, but stupid! Go for Dollars :P Same with TimeFrame and Interest.
Next up is a nice learning moment.
while (y<u) { y= y + 1; x= x*(p*0.01) + x; }
is really nice, but has some ways of making it more funky :D
y = y + 1; Can change to y += 1; Or if you're really lazy y++;
while loop to for loop.
for (int y=0; y<u; y++) // no need to predefine y { x += (x*(p*0.01)); // Personal, looks neat, easy to read, bit of added safety }
Also, I wouldn't use a do while loop, because they confuse people, using while is easier to read, and also shorter to write :P
And what if I an just lazy, and press just an n/N, or write no like No, nO or even NO!
Final thing, use the Tab and Enter more in your code, make is easier to read, I use 1 empty line after includes, then 2 after my variables.
cout << "How many dollars would you like to calculate?" << endl; cin >> Dollars;
cout << "How many years would you like to calculate?" << endl; cin >> Time;
cout << "How much interest per year would you like?" << endl; cin >> Interest;
for (int y=0; y<Time; y++) {
Dollars += (Dollars*(Interest*0.01)); }
Programming is for lazy people only! Don't make it hard, keep it simple.
|
Online Status: Offline
|
|
| |
| mikehauncho |
| Posted: 25-November-2007 at 3:59pm | IP Logged
|
|
|
Newbie

Group: Newbie
Joined: 10-November-2007 Location: United States Posts: 8
|
DutchDude wrote:
Nice idea, but some small ideas.
Use a double for x, maybe people need bigger numbers, think of companies!
in fact, don't use x, give it a real name, call it Dollars, or AmountOfMoneyPeopleSayTheyHave, but the last one is stupid, legal, but stupid! Go for Dollars :P Same with TimeFrame and Interest.
Next up is a nice learning moment.
while (y<u) { y= y + 1; x= x*(p*0.01) + x; }
is really nice, but has some ways of making it more funky :D
y = y + 1; Can change to y += 1; Or if you're really lazy y++;
while loop to for loop.
for (int y=0; y<u; y++) // no need to predefine y { x += (x*(p*0.01)); // Personal, looks neat, easy to read, bit of added safety }
Also, I wouldn't use a do while loop, because they confuse people, using while is easier to read, and also shorter to write :P
And what if I an just lazy, and press just an n/N, or write no like No, nO or even NO!
Final thing, use the Tab and Enter more in your code, make is easier to read, I use 1 empty line after includes, then 2 after my variables.
cout << "How many dollars would you like to calculate?" << endl; cin >> Dollars;
cout << "How many years would you like to calculate?" << endl; cin >> Time;
cout << "How much interest per year would you like?" << endl; cin >> Interest;
for (int y=0; y<Time; y++) {
Dollars += (Dollars*(Interest*0.01)); }
Programming is for lazy people only! Don't make it hard, keep it simple.
|
|
|
ya, i was just having a really hard time finding a method to calculate the interest taking into account the years but very good input, thanks alot (its a now i know moment)
|
Online Status: Offline
|
|
| |
| 1 User(s) are browsing this topic, 1 Guest(s) and 0 Member(s) |
| 0 Members: |
|
|
|
|
|
If you wish to post a reply to this topic you must first login If you are not already registered you must first register
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum
|
This page was generated in 0.2031 seconds. |