Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7093683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:28:12+00:00 2026-05-28T08:28:12+00:00

first off this is a class assignment so i would appreciate help but just

  • 0

first off this is a class assignment so i would appreciate help but just hints as i want to learn. I have to calculate monthly payment based off of interest rate etc as seen in my code but something is off with my calculation. My output reads nan which i believe is not a number. I have been trying to figure out where i am going wrong to no avail,any suggestions on how to correct this issue? Thanks in advance.

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

int main()
{
    //collect payment info
    double loanAmount = 0; 
    double anualRate = 0;
    double monthlyIntRate = 0; 
    int numOfPayment = 0; 
    double monthlyPayment = 0; 
    double amountPaidBack = 0; 
    double interestPaid = 0;

    cout << "Enter loan amount: ";
    cin >> loanAmount;
    cout << "Enter Anual Interest Rate: ";
    cin >> anualRate;
    cout << "Enter Payments made: ";
    cin >> numOfPayment;

    //calculate montly payment
    monthlyPayment = (loanAmount * pow(monthlyIntRate + 1, numOfPayment) * monthlyIntRate) / ( pow(monthlyIntRate + 1, numOfPayment) - 1);                                                    

    //calculate amount paid back
    amountPaidBack = monthlyPayment * numOfPayment;

    //calculate interest paid
    monthlyIntRate = anualRate / 12;
    interestPaid = monthlyIntRate * numOfPayment;

    //split input from calculated output
    cout << "-----------------------------\n" << endl;

    //Display the calulated data
    cout << fixed;
    cout << setprecision(2);

    cout << "Loan Amount: " << setw(15) << "$ "<< right << loanAmount << endl;

    cout << "Monthly Interest Rate: " << setw(14) << monthlyIntRate << "%" << endl;

    cout << "Number of Payments: " << setw(17) << numOfPayment << endl;

    cout << "Montly Payment: " << setw(19) << "$ " << monthlyPayment << endl;

    cout << "Amount Paid Back: " << setw(17) << "$ " << amountPaidBack << endl;

    cout << "Interest Paid: " << setw(18) << "$ " << interestPaid << endl;

    return 0;

Output:

Loan Amount:              $ 100000.00
Monthly Interest Rate:           1.00%
Number of Payments:                36
Montly Payment:                  $ nan
Amount Paid Back:                $ nan
Interest Paid:                 $ 36.00
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:28:13+00:00Added an answer on May 28, 2026 at 8:28 am

    You’re dividing by zero. it occurs in this line:

    monthlyPayment = (loanAmount * pow(monthlyIntRate + 1, numOfPayment) * monthlyIntRate) / ( pow(monthlyIntRate + 1, numOfPayment) - 1);
    

    The value stored in monthlyIntRate is zero, so pow(monthlyIntRate + 1, numOfPayment) eqauls to (0 + 1) ^ numOfPayment, which is 1. So, pow(monthlyIntRate + 1, numOfPayment) - 1) is 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off the html row looks like this: <tr class=evenColor> blahblah TheTextIneed blahblah and
First off, I'm aware this is a bad practice and I have answered many
I have to use SQLPLUS for my database class, and our first assignment is
First off, I know I can copy "this" on instantiation, but that doesn't work
First off, I think this is somewhat ridiculous to do but the other members
First off, this question is ripped out from this question. I did it because
First off, this is NOT a duplicate of: Turn a C string with NULL
First off, I apologize if this doesn't make sense. I'm new to XHTML, CSS
First off, let me preface this question by stating that I'm really a pretty
First off, I am running this on a dual core 2.66Ghz processor machine. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.