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

  • Home
  • SEARCH
  • 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 7771701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:42:59+00:00 2026-06-01T16:42:59+00:00

So my for loop causes a crash and I know exactly why, but I’m

  • 0

So my for loop causes a crash and I know exactly why, but I’m unsure of a way to rewrite this to get it to do what I’m trying to accomplish.

I’m trying to get it to take out money from a compounding interest each day and total it up for the month (which is set for ever 30 days). The user inputs the number of days they are trying to calculate for. So what is causing the crash is if they put in anything other than something divisible by 30.

I’m having difficulty coming up with a way to rewrite this and could use any suggestions. I would like it to do something if they put in 65 it calculates 2 months worth and then display like insuficiant days for month 3. Any help is always greatly appreciated. Thanks in advance.

for (int i = 0; i < numDays; i+=30){
    double cash=0;
    for (int n=1; n < 30; n++){
        int currentDay;
        currentDay= n+i;
        cash=cash+dailyMoney[currentDay];
    }
    month++;
    if(monthlyChecks == null)
        monthlyChecks = "\nCheck on month "+month+": $"+df.format(cash)+"\n";
    else 
        monthlyChecks = monthlyChecks+"\nCheck on month "+month+": $"+df.format(cash)+"\n";
}

numDays is the user inputted number of days….
monthlyChecks is a String….
dailyMoney[] is the array that holds the amount for each day.

  • 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-01T16:43:00+00:00Added an answer on June 1, 2026 at 4:43 pm

    Okay, sounds to me like what you are trying to do with your “insufficient days for month 3” is this: (Assuming numDays is an int)

    numMonths = numDays / 30 //If numDays is an int, this will round down.
    extraDays = numDays % 30
    
    for (int i = 0; i < numMonths; i+=30){
       double cash=0;
       for (int n=1; n < 30; n++){
          int currentDay;
          currentDay= n+i;
    
          cash=cash+dailyMoney[currentDay];
       }
       month++;
       if(monthlyChecks == null)
          monthlyChecks = "\nCheck on month "+month+": $"+df.format(cash)+"\n";
       else 
          monthlyChecks = monthlyChecks+"\nCheck on month "+month+": $"+df.format(cash)+"\n";
       }
    }
    
    //Then at some point
    Systme.out.println("Insuffiecent days for " + numMonth + 1 " months. " + 30 - extraDays " days short).")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to do this: arrCauses := APEX_UTIL.STRING_TO_TABLE(:P1_CAUSE); FOR c IN 1..arrCauses.count LOOP
This loop works fine in Main function but when copy this loop code in
Loop unwinding is a common way to help the compiler to optimize performance. I
/// \todo Loop must be rewritten ... /// \todo Delete this loop Can Doxygen
This loop checks if a record is in the sqlite database and builds a
This loop is strange. I ran this in Java, it gives an Index out
This link describes my problem exactly: http://old.nabble.com/Android-database-corruption-td28044218.html#a28044218 There are about 300 people using my
I'm having this log (of course with the crash of my activity :D )
I have released my app to Market yesterday and I get a strange crash
This feels like a newbie issue, but I can't seem to figure it out.

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.