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 8636975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:21:47+00:00 2026-06-12T10:21:47+00:00

I was going through a code used to calculate investments until it has doubled

  • 0

I was going through a code used to calculate investments until it has doubled and I received an infinite loop that I can’t seem to solve. Can anyone figure out why this is giving me an infinite loop? I’ve gone through myself but I can’t seem to find the problem. The “period” referred is how many times per year the interest is compounded.

double account = 0; //declares the variables to be used
   double base = 0;
   double interest = 0;
   double rate = 0;
   double result = 0;
   double times = 0;
   int years = 0;
   int j;

   System.out.println("This is a program that calculates interest.");
   Scanner kbReader = new Scanner(System.in); //enters in all data  
   System.out.print("Enter account balance: ");
   account = kbReader.nextDouble();
   System.out.print("Enter interest rate (as decimal): ");
   rate = kbReader.nextDouble();

   System.out.println("                    " + "Years to double" + "     " +     "Ending balance");
   base = account;
   result = account;
   for (j=0; j<3; j++){
       System.out.print("Enter period: ");
       times = kbReader.nextDouble();
       while (account < base*2){
           interest = account * rate / times;
           account = interest + base;
           years++;
       }
        account = (((int)(account * 100))/100.0);
       //results
       System.out.print("                         " + i + "               " + account + "\n");
       account = result;
   }

The code should ask for three “periods”, or three different times the entered data is compounded per year (ex annually, monthly, daily etc.)

Thanks a lot!

  • 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-06-12T10:21:49+00:00Added an answer on June 12, 2026 at 10:21 am

    Instead of doing

    account =interest +base
    

    You should have

    account = interest +account
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After going through Marshall code snippet Got the Idea that marshalling is used to
I was going through some code that I downloaded off the internet ( Got
I was going through the source code of ArrayBlockingQueue and LinkedBlockingQueue. LinkedBlockingQueue has a
I'm going through a Fortran code, and one bit has me a little puzzled.
I was going through some code and noticed that UPDATE LOW_PRIORITY and INSERT DELAYED
I'm going through a Django book and I seem to be stuck. The code
I was going through code walk through in which I have discovered that an
I was just going through one code used to draw one chart. This code
The following is a simple bit of code that can be used to create
Here's some code in a django tutorial that I'm going through. I've never come

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.