473,398 Members | 2,113 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,398 software developers and data experts.

incorrect answer

I have been working on this program for a few days now, and I am at a loss as to what is wrong. I am new to c++, so I am sure that it must be something simple that I am missing, but I can not pin point it. Below is my code, and no matter what I input it gives me the same answer: $1.#INF. All I need for it to do is calculate the monthly payments .


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std ;
  4. //function prototype
  5. double payment(double balance, double AIR, int num_of_pay);
  6. //funciton prototype
  7. double power (int num_of_pay, double AIR);
  8. int main ()
  9. {
  10.   double month_pay; //
  11.   double balance; //amount of loan
  12.   double AIR; //annual interest rate
  13.   int num_of_pay ; //number of payments over course of loan
  14.   double result;
  15.  
  16.   cout<< "Welcome to the loan payment calculator program!"<<endl ;
  17.  
  18.   cout<< " Please enter the loan amount:"<<endl ;
  19.   cin>> balance;
  20.  
  21.    cout<< " Please enter the annual interest rate as a percentage, not a decimal:"<<endl; 
  22.    cin>> AIR;
  23.  
  24.    cout<< "Please enter number of payments you will pay:"<<endl;
  25.    cin>> num_of_pay;
  26.    month_pay = payment(balance, AIR, num_of_pay);
  27.    cout<< "The amount of your monthly payment is:  $" << month_pay <<endl;
  28.  
  29.    system("PAUSE");
  30.    return (0);
  31. }
  32.  
  33. double payment(double balance, double AIR, int num_of_pay)
  34. {
  35.  
  36.     double month_pay;
  37.  
  38.    AIR = (AIR/100.00)/12.00;
  39.  
  40.    month_pay = (balance * AIR) / ( 1.0 - power ((! + AIR), -num_of_pay));
  41.  
  42.    return (month_pay);
  43. }
  44.  
  45.  
  46. double power (int num_of_pay, double AIR)
  47. {
  48.     double result;
  49.     int i;
  50.  
  51.     result = 1.0;
  52.     for (i=0; i< abs (num_of_pay); i++) result *= (1 + AIR );
  53.  
  54.     if (num_of_pay > 0)
  55.         return (result);
  56.     else
  57.         return (1.0 / result);
  58. }
Dec 14 '07 #1
3 1237
what do you pass to the program?
Dec 14 '07 #2
what do you pass to the program?

I pass the amount of the loan. We'll say 5700. The amount of interest, we'll say 12 . And the amount of total payments, we'll say 36.
Dec 14 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
month_pay = (balance * AIR) / ( 1.0 - power ((! + AIR), -num_of_pay));
So, what's the ! for ??? .....................................^
Dec 17 '07 #4

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

Similar topics

2
by: Tom Haddon | last post by:
Hi Folks, When I run: print "%0.2f" % ((16160698368/1024/1024/1024),) I get 15.00 I should be getting 15.05. Can anyone tell me why I'm not?
1
by: Amit D.Shinde | last post by:
Hi Experts, i am writting a stored procedure in sql server 7. Its a simple stored procedure It is my first stored procedure. I want insert a record in table if the primary key field user id...
5
by: Christoph | last post by:
alert( 100 * 1.15 ); The above *should* show a value of 115. However, what I am actually getting is: 114.99999999999998 alert( 100 * 1.10 ); is showing as:
3
by: SimonDB | last post by:
The replication of my database was successful and it works well. I can modify tables and forms, except for one thing : VBA ! I can’t add code in VBA, the error message : "incorrect data format". I...
13
by: Yogesh Khanolkar | last post by:
Hi, I am getting incorrect o/p from the code below: #include<stdio.h> #include<float.h> #include<limits.h> main() { double val,val1;
11
by: Mark Findlay | last post by:
Hello Experts! I am attempting to use the OleDbCommand.ExecuteScaler() function within my ASP.NET C# web page to perform a simple validation, but receive the following error: "Incorrect...
6
by: ypjofficial | last post by:
HI, I have following terrific confusion. class test { public: int i; int * j; int **k;
1
by: piruk | last post by:
I have to write a program in c++, which write lots of data. I use int, double and string. How to protect the program before incorrect input data? What is the best way? piruk
3
lee123
by: lee123 | last post by:
I have a problem getting the correct to count +1 every time I get an answer right and the incorrect is the same. I have two lbl's named number1 and number2 which produces a Rnd# in each lbl. ...
1
by: TonyJ | last post by:
Hello! If I have a control in the form that is accessed by a different thread then the one that was used when the control was created I get "Cross-thread operation not valid: Control 'digital'...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.