Very simple, only took me about 45 minutes to make.
Tell me if there are any glitches.
Make sure you've got the C++ runtime files.
Yes, I know it's a console application.
Tell me of any glitches you find.
Download: project2.zip
(make sure you extract it)
Source Code ( you can steal, don't really care )
Code:#include <iostream.h> #include <math.h> void anually(double principal, double rate, double years, double leftover) { cout<<"You have chosen anually."<<endl; cout<<"Final account balance after " <<years<<" years is: "<<principal*pow((1+(rate/100)/1), 1*years)<<endl; leftover= principal*pow((1+(rate/100)/1), 1*years); cout<<"Interest accrued: "<<leftover - principal<<endl; } void semianually(double principal, double rate, double years, double leftover) { cout<<"You have chosen semianually."<<endl; cout<<"Final account balance after " <<years<<" years is: "<<principal*pow((1+(rate/100)/2), 2*years)<<endl; leftover= principal*pow((1+(rate/100)/2), 2*years); cout<<"Interest accrued: "<<leftover - principal<<endl; } void quart(double principal, double rate, double years, double leftover) { cout<<"You have chosen quarterly."<<endl; cout<<"Final account balance after " <<years<<" years is: "<<principal*pow((1+(rate/100)/4), 4*years)<<endl; leftover= principal*pow((1+(rate/100)/4), 4*years); cout<<"Interest accrued: "<<leftover - principal<<endl; } void month(double principal, double rate, double years, double leftover) { cout<<"You have chosen monthly."<<endl; cout<<"Final account balance after " <<years<<" years is: "<<principal*pow((1+(rate/100)/12), 12*years)<<endl; leftover= principal*pow((1+(rate/100)/12), 12*years); cout<<"Interest accrued: "<<leftover - principal<<endl; } void weekly(double principal, double rate, double years, double leftover) { cout<<"You have chosen weekly."<<endl; cout<<"Final account balance after " <<years<<" years is: "<<principal*pow((1+(rate/100)/52), 52*years)<<endl; leftover= principal*pow((1+(rate/100)/52), 52*years); cout<<"Interest accrued: "<<leftover - principal<<endl; } void daily(double principal, double rate, double years, double leftover) { cout<<"You have chosen daily."<<endl; cout<<"Final account balance after " <<years<<" years is: "<<principal*pow((1+(rate/100)/365), 365*years)<<endl; leftover= principal*pow((1+(rate/100)/365), 365*years); cout<<"Interest accrued: "<<leftover - principal<<endl; } void contin(double principal, double rate, double years, double leftover) { cout<<"You have chosen continuously."<<endl; cout<<"Final account balance after "<<years<<" years is: "<<principal*pow(2.71828183,((rate/100)*years))<<endl; leftover=principal*pow(2.71828183,((rate/100)*years)); cout<<"Interest accrued: "<<leftover - principal<<endl; } void ntimes(double principal, double rate, double years, double leftover, double nt) { cout<< "Enter number of times compounded per year: "; cin>>nt; cout<< "Final account balance after "<<years<<" years is: "<<principal*pow((1+(rate/100)/nt), nt*years)<<endl; leftover=principal*pow((1+(rate/100)/nt), nt*years); cout<<"Interest accrued: "<<leftover - principal<<endl; } int main() { double principal, rate, years, op, leftover, nt; cout<<" Interest Calculator."<<endl; cout<<" Made by Robyn :)"<<endl<<endl; cout<<"This is a simple program that calculates interest."<<endl; cout<<"For the most part, it's self explanitory, just input your values when prompted."<<endl; cout<<"Hit enter after you input something to continue to the next step."<<endl; cout<<"-------------------------------------------------------------------------------"<<endl; cout<<endl; while(op!=9) { cout<<"Enter a starting balance: "; cin>>principal; while(principal<1) { cout<<"You probably want to start out with at least 1 dollar. Just a guess."<<endl; cout<<"So, try again: "; cin>>principal; cout<<endl; } cout<<"Enter percent interest rate: "; cin>>rate; while(rate<.1) { cout<<"You probably want to have more than a 0% interest rate. Just a guess"<<endl; cout<<"So, try again: "; cin>>rate; cout<<endl; } cout<<"Enter number of years in the account: "; cin>>years; while(years<.003) { cout<<"You probably want to have it for at least a day. Just a suggestion."<<endl; cout<<"So, try again: "; cin>>years; cout<<endl; } cout<<"Select number of times per year interest is compounded:"<<endl; cout<<" 1. Anually"<<endl; cout<<" 2. Semianually"<<endl; cout<<" 3. Quarterly"<<endl; cout<<" 4. Monthly"<<endl; cout<<" 5. Weekly"<<endl; cout<<" 6. Daily"<<endl; cout<<" 7. Continuously"<<endl; cout<<" 8. Another amount"<<endl; cout<<" OR"<<endl; cout<<" 9. Quit the program"<<endl; cout<<"Choice: "; cin>>op; cout<<endl; if(op==1) { anually(principal, rate, years, leftover); cout<<endl; } else if(op==2) { semianually(principal, rate, years, leftover); cout<<endl; } else if(op==3) { quart(principal, rate, years, leftover); cout<<endl; } else if(op==4) { month(principal, rate, years, leftover); cout<<endl; } else if(op==5) { weekly(principal, rate, years, leftover); cout<<endl; } else if(op==6) { daily(principal, rate, years, leftover); cout<<endl; } else if(op==7) { contin(principal, rate, years, leftover); cout<<endl; } else if(op==8) { ntimes(principal, rate, years, leftover, nt); cout<<endl; } else if(op<1||op>9) { cout<<"No, only an option 1-9. The program will now restart."<<endl; cout<<endl; } system ("PAUSE"); cout<<endl; } return 0; }
Results 1 to 3 of 3
Thread: My Interest Calculator. [C++]
- 25 Mar. 2010 10:14pm #1
My Interest Calculator. [C++]
LG's Dyke. Enough. Said.
- 25 Mar. 2010 11:20pm #2
I been lookin for one of these.
- 26 Mar. 2010 12:04am #3