473,386 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

For loops(financial Application) in C++

2
user need to enter loan amount and periods number of years.The interest is fixed 5% to 8% , with an increment of 1/8. for loop, c++.


i have write the program but something wrong on it.

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
double interestRate;
double loanAmount;
double numberOfYears;
double monthlyPayment;
double totalPayment;

cout <<" Interest rate Monthly Payment Total payment\n";

//Display the table body

for (int interestRate = 5.0 ; interestRate <= 8.0 ; interestRate+=0.125)
cout << setw(3) << fixed << interestRate;
cin >> interestRate;
cout<<" \n";


// Prompt user to enter loan amount
cout <<" Enter loan amount : " << endl;
cin >> loanAmount;

// Prompt user to enter years
cout <<" Enter number of Years : " << endl;
cin >> numberOfYears ;

// Calculate payment
int i;
for( i = numberOfYears ; i < monthlyPayment ; i++)
{
double monthlyPayment = (loanAmount * interestRate) / ( 1.0 - 1.0 / pow(1.0 + interestRate , numberOfYears * 12.0));
monthlyPayment = static_cast<int>(monthlyPayment * 100) / 100.0;
cout << setw(3) << monthlyPayment << i;
cout <<" \n ";
}

int j;
for (j= numberOfYears; j < totalPayment ; j++;)
{
double totalPayment = monthlyPayment * numberOfYears * 12.0;
totalPayment = static_cast<int>(totalPayment * 100) / 100.0;
cout << setw(3) << j;
cout << " \n ";
}



return 0;
}
Jun 28 '15 #1
2 1338
weaknessforcats
9,208 Expert Mod 8TB
Time to learn how to use your debugger.

I'm short of time right now but I do see places where you move a double to an int. Your compiler should be giving you a warning here since you cannot assign a double to an int. ints have no decimal places so an accurate assignment is not possible.

Some of your calculations are mixing int and double values. Everything should be all int or all floating point.

BTW: Finance calculations don't work well with floating point because of the rounding. Good finance code will use only int with the amount kept in pennies. So 123 is $1.23.

You only need to see the decimal point when you display the int:

value/100 is the dollars.
value %100 are the pennies

The code looks like:

cout << "$" << value/100 << "." << value $100;

On the screen you see $1.23

Post again and I will take a second look.
Jun 28 '15 #2
XD05
2
ermm
i wan to get my ans like this

for example:
Enter:
Loan Amount: 10000
Number of years: 5

Result:
Interest rate , Monthly Payment , Total payment
5% , 188.71 , 11322.74
5.125% , 189.28 , 11357.13
5.25% , 189.85 , 11391.59
……
7.85% , 202.16 , 12129.97
8.0% , 202.76 , 12165.83
Jun 28 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

33
by: aa | last post by:
I am migrating to PHP from ASP where there are the Application Scope variables which are accessible from any page on a website and which are used, in particular, for hit counters. Is there a similar...
8
by: BMM | last post by:
Hi. I have a dumb question. Is a database an application? And, in the context of a data-driven web-enabled application, is the database still an application? I have a project lead who says it is....
9
by: J. Baute | last post by:
I'm caching data in the Application object to speed up certain pages on a website The main reason is that the retrieval of this data takes quite a while (a few seconds) and fetching the same data...
1
by: Guinness Mann | last post by:
Pardon me if this is not the optimum newsgroup for this post, but it's the only .NET newsgroup I read and I'm certain someone here can help me. I have a C# program that checks for an error...
3
by: Amit Dedhia | last post by:
Hi I am developing a Dot net application (involving image processing) on a uni processor. It works well on my machine. I then take all my code on a multi processor, build and run the application...
2
by: evangeline | last post by:
We have ASP application running on IIS 5.1 and Windows 2000 server. The ASP application has few Application variables setup in global.asa. Something like this: Application.Lock()...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
20
by: Peter Oliphant | last post by:
How does one launch multiple forms in an application? Using Photoshop as an example, this application seems to be composed of many 'disjoint' forms. Yet, they all seem somewhat 'active' in...
4
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.