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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:51:24+00:00 2026-05-31T21:51:24+00:00

I am having issues with one of my outputs in my program. The issue

  • 0

I am having issues with one of my outputs in my program. The issue stems from one of my outputs bypassing the nested do/while loop that is inside another do/while loop. I can put that first output statement inside the nested do/while loop. The problem with doing that is it will give me two output messages rather than one based on my calculations. Unfortunately the program is kind of long since everything is in main.

import java.util.Scanner;   //CAPTURES USERS INPUT VIA THE KEYBOARD

public class practice
{

public practice()
{

}

public static void main(String[] args)
{

    char response = 0; //STORES USERS RESPONSE
    int attempt = 1; //LOOP CONTROL VARIABLE FOR OUTER DO WHILE LOOP
    int attempts = 1; //LOOP CONTROL VARIABLE FOR INNER DO WHILE LOOP
    double grossAnnualIncome = 0.0; //STORES USERS GROSS ANNUAL INCOME
    double annualTuition = 0.0; //STORES USERS ANNUAL TUITION PAYMENTS
    double annualCharity = 0.0; //STORES USERS ANNUAL DONATIONS TO CHARITY
    double homeMortgage = 0.0; //STORES USERS ANNUAL HOME MORTGAGE PAYMENTS
    double healthCredit = 0.0; //STORES USERS HEALTH INSURANCE CREDIT
    double annualAfterTaxes = 0.0; //STORES USERS ANNUAL INCOME AFTER TAXES
    double monthlyAfterTaxes = 0.0; //STORES USERS MONTHLY INCOME AFTER TAXES
    double taxOwed = 0.0; //STORES USERS TAX RATE AT A FIXED RATE OF 17%
    double taxableIncome = 0.0; //STORES USERS TAXABLE INCOME
    double taxCredits = 0.0; //STORES ALL OF THE USERS TAX CREDITS ADDED TOGETHER

    Scanner input = new Scanner(System.in); //ALLOWS THE USER TO ENTER THEIR CURRENT TAX INFORMATION

    do
    {
        do
        {

        System.out.print( "\nPlease enter your gross annual income or 0 for none:  " ); //PROMPT 1
        grossAnnualIncome = input.nextDouble();

            if( grossAnnualIncome > 0 )
            {

            System.out.print( "\nPlease enter your annual tuition and expenses for higher education or 0 for none:  ");
            annualTuition = input.nextDouble();

        System.out.print( "\nPlease enter your annual charitable contributions or 0 for none:  ");
            annualCharity = input.nextDouble();

            System.out.print( "\nPlease enter the annual interest paid for your home mortgage or 0 for none:  ");
            homeMortgage = input.nextDouble();
            input.nextLine();

            System.out.print( "\nDid you purchase health insurance through your employer or outside the workplace?"
              + " Enter 'Y' or 'N':  ");
        response = input.nextLine().charAt(0);


                if( Character.toUpperCase(response) == 'Y' )
                {

                System.out.print( "\nAre you filing as a family?  Enter 'Y' or 'N':  "); //PROMPT 6
                response = input.nextLine().charAt(0);

                    if ( Character.toUpperCase(response) == 'Y' )
                    {

                    healthCredit = 3500;
                    }

                else
                {

                    if( Character.toUpperCase(response) == 'N' )
                        {

                        System.out.print( "\nAre you filing as single?  Enter 'Y' or 'N':  "); //PROMPT 7
                        response = input.nextLine().charAt(0);

                        }

                            if( Character.toUpperCase(response) == 'Y')
                            {

                            healthCredit = 2000;
                            }

                }

                }
                else
                {

                healthCredit = 0;
                }

                System.out.printf( "\nAre the following entries correct?\n\n"
                            + "Gross Annual Income:  $%,.0f\n\n"
                            + "Deductions: \n"
                            + "\tHigher Education:  %,.0f\n"
                            + "\tCharitable Contributions:  %,.0f\n"
                            + "\tHome Mortgage Interest:  %,.0f\n"
                            + "\tHealth Insurance Tax Credit:  %,.0f\n\n", grossAnnualIncome, annualTuition,                                    annualCharity, homeMortgage, healthCredit);

                System.out.print( "\nEnter 'Y' or 'N': ");
                response = input.nextLine().charAt(0);
            }

            if( Character.toUpperCase(response) == 'Y')
        {

            --attempts;

        }

        }while( attempts == 1);


                //CALCULATIONS
    taxableIncome  = grossAnnualIncome - taxCredits;
        taxOwed = taxableIncome * .17; //TAKES TAXABLE INCOME AND MULTIPLIES IT BY A 17% FLAT TAX RATE
        annualAfterTaxes = grossAnnualIncome - taxOwed; //TAKES USERS GROSS ANNUAL INCOME SUBTRACTED BY 17% TAX BRACKET
        monthlyAfterTaxes  = annualAfterTaxes  / 12; //DIVIDES THE USERS ANNUAL GROSS AFTER TAXES BY 12 FOR MONTHLY GROSS
        taxCredits = annualTuition + annualCharity + homeMortgage + healthCredit; //ADDS UP THE USERS TOTAL ANNUAL TAX

    if( grossAnnualIncome == 0 )
    {

    System.out.print( "\nYou earned no income so you owe no taxes!" ); //GROSS ANNUAL INCOME EQUALS ZERO OUTPUT
    input.nextLine();
    }

    else if(grossAnnualIncome <= taxCredits )
    {

    System.out.print( "\nYOU OWE $0.00 IN TAXES!" ); //GROSS ANNUAL INCOME LESS THAN OR EQUAL TO TAX CREDITS OUTPUT
    }

    else
    {


            //GROSS ANNUAL INCOME GREATER THAN ZERO OUTPUT
    System.out.printf( "\n\nYOUR TAXES\n\n"
                    + "Gross Annual Income:  $%,.0f\n\n"
                    + "Deductions: \n"
                    + "\tHigher Education:  %,.0f\n"
                    + "\tCharitable Contributions:  %,.0f\n"
                    + "\tHome Mortgage Interest:  %,.0f\n"
                    + "\tHealth Insurance Tax Credit:  %,.0f\n\n"
                    + "Tax at 17%%:  $%,.0f\n"
                    + "Annual Income After Tax:  $%,.0f\n"
                    + "Monthly Income After Tax:  $%,.0f", grossAnnualIncome, annualTuition, annualCharity,
                       homeMortgage, healthCredit, taxOwed, annualAfterTaxes, monthlyAfterTaxes);

    }

 System.out.print( "\n\nDo you want to calculate taxes for someone else?  Enter 'Y' or 'N' ");
     response = input.nextLine().charAt(0);

    if( Character.toUpperCase(response) == 'N')
    {

        --attempt;
    }

}while(attempt == 1);

System.exit(0);

}

}

Again I’m sorry for how long the code is. The exact issue I am having is that when the user enters 0 at the first prompt(without entering the nested do/while loop) it just loops:

Please enter your gross annual income or 0 for none:  0

Please enter your gross annual income or 0 for none:  0

Please enter your gross annual income or 0 for none:  0 

Now if I move:

if( grossAnnualIncome == 0 )
{

System.out.print( "\nYou earned no income so you owe no taxes!" );
input.nextLine();
break;
}

into the nested do/while loop I get:

Please enter your gross annual income or 0 for none:  0

You earned no income so you owe no taxes!
YOU OWE $0.00 IN TAXES!

When it should only read the 1st output.

The Correct output should look like:

Please enter your gross annual income or 0 for none:  0

You earned no income so you owe no taxes!

Thank you in advance.

  • 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-31T21:51:25+00:00Added an answer on May 31, 2026 at 9:51 pm

    If a user enters ‘0’ none of the inner if statements are hit, attempts will not change, so you keep running the same loop.

    update:
    Let me say first that this is horribly, horribly wrong, but this should work. I changed your loop control to a boolean, moved a couple of things around. Besides the total lack of oop going on here (an entity class would work much better), your scanner input will behave unpredictably if the user selects enter.
    This is by no means bulletproof.

    import java.util.Scanner;   //CAPTURES USERS INPUT VIA THE KEYBOARD
    
    public class PracticeFromStackOverFlow
    {
    
    public PracticeFromStackOverFlow()
    {
    
    }
    
    public static void main(String[] args)
    {
    
        char response = 0; //STORES USERS RESPONSE
        boolean outerLoop = true; //LOOP CONTROL VARIABLE FOR OUTER DO WHILE LOOP
        boolean innerLoop = true; //LOOP CONTROL VARIABLE FOR INNER DO WHILE LOOP
        double grossAnnualIncome = 0.0; //STORES USERS GROSS ANNUAL INCOME
        double annualTuition = 0.0; //STORES USERS ANNUAL TUITION PAYMENTS
        double annualCharity = 0.0; //STORES USERS ANNUAL DONATIONS TO CHARITY
        double homeMortgage = 0.0; //STORES USERS ANNUAL HOME MORTGAGE PAYMENTS
        double healthCredit = 0.0; //STORES USERS HEALTH INSURANCE CREDIT
        double annualAfterTaxes = 0.0; //STORES USERS ANNUAL INCOME AFTER TAXES
        double monthlyAfterTaxes = 0.0; //STORES USERS MONTHLY INCOME AFTER TAXES
        double taxOwed = 0.0; //STORES USERS TAX RATE AT A FIXED RATE OF 17%
        double taxableIncome = 0.0; //STORES USERS TAXABLE INCOME
        double taxCredits = 0.0; //STORES ALL OF THE USERS TAX CREDITS ADDED TOGETHER
    
        Scanner input = new Scanner(System.in); //ALLOWS THE USER TO ENTER THEIR CURRENT TAX INFORMATION
    
        while(outerLoop)
        {
            innerLoop = true; // reset this every time you 
            while(innerLoop) {
    
                System.out.print( "\nPlease enter your gross annual income or 0 for none:  " ); //PROMPT 1
                grossAnnualIncome = input.nextDouble();
    
                if( grossAnnualIncome > 0 ) {
    
                    System.out.print( "\nPlease enter your annual tuition and expenses for higher education or 0 for none:  ");
                    annualTuition = input.nextDouble();
    
                    System.out.print( "\nPlease enter your annual charitable contributions or 0 for none:  ");
                    annualCharity = input.nextDouble();
    
                    System.out.print( "\nPlease enter the annual interest paid for your home mortgage or 0 for none:  ");
                    homeMortgage = input.nextDouble();
                    input.nextLine();
    
                    System.out.print( "\nDid you purchase health insurance through your employer or outside the workplace?"
                            + " Enter 'Y' or 'N':  ");
                    response = input.nextLine().charAt(0);
                    healthCredit = 0;
    
                    if( Character.toUpperCase(response) == 'Y' ) {
    
                        System.out.print( "\nAre you filing as a family?  Enter 'Y' or 'N':  "); //PROMPT 6
                        response = input.nextLine().charAt(0);
    
    
                        if ( Character.toUpperCase(response) == 'Y' ) {
    
                            healthCredit = 3500;
                        } else { // do you really need this?  
    
                            if( Character.toUpperCase(response) == 'N' ) {
    
                                System.out.print( "\nAre you filing as single?  Enter 'Y' or 'N':  "); //PROMPT 7
                                response = input.nextLine().charAt(0);
                            }
    
                            if( Character.toUpperCase(response) == 'Y') {
    
                                healthCredit = 2000;
                            }
    
                        }
    
                    } 
    
                    System.out.printf( "\nAre the following entries correct?\n\n"
                            + "Gross Annual Income:  $%,.0f\n\n"
                            + "Deductions: \n"
                            + "\tHigher Education:  %,.0f\n"
                            + "\tCharitable Contributions:  %,.0f\n"
                            + "\tHome Mortgage Interest:  %,.0f\n"
                            + "\tHealth Insurance Tax Credit:  %,.0f\n\n", grossAnnualIncome, annualTuition,                                    annualCharity, homeMortgage, healthCredit);
    
                    System.out.print( "\nEnter 'Y' or 'N': ");
                    response = input.nextLine().charAt(0);
    
                    if( Character.toUpperCase(response) == 'Y'){
                        innerLoop = false;
    
                    }
                } else {
                    innerLoop = false;
                }
            }
    
    
                    //CALCULATIONS
        taxableIncome  = grossAnnualIncome - taxCredits;
            taxOwed = taxableIncome * .17; //TAKES TAXABLE INCOME AND MULTIPLIES IT BY A 17% FLAT TAX RATE
            annualAfterTaxes = grossAnnualIncome - taxOwed; //TAKES USERS GROSS ANNUAL INCOME SUBTRACTED BY 17% TAX BRACKET
            monthlyAfterTaxes  = annualAfterTaxes  / 12; //DIVIDES THE USERS ANNUAL GROSS AFTER TAXES BY 12 FOR MONTHLY GROSS
            taxCredits = annualTuition + annualCharity + homeMortgage + healthCredit; //ADDS UP THE USERS TOTAL ANNUAL TAX
    
        if( grossAnnualIncome == 0 ) {
    
            System.out.print( "\nYou earned no income so you owe no taxes!" ); //GROSS ANNUAL INCOME EQUALS ZERO OUTPUT
            input.nextLine();
        }
    
        else if(grossAnnualIncome <= taxCredits ) {
            System.out.print( "\nYOU OWE $0.00 IN TAXES!" ); //GROSS ANNUAL INCOME LESS THAN OR EQUAL TO TAX CREDITS OUTPUT
        }
    
        else {
    
    
                //GROSS ANNUAL INCOME GREATER THAN ZERO OUTPUT
        System.out.printf( "\n\nYOUR TAXES\n\n"
                        + "Gross Annual Income:  $%,.0f\n\n"
                        + "Deductions: \n"
                        + "\tHigher Education:  %,.0f\n"
                        + "\tCharitable Contributions:  %,.0f\n"
                        + "\tHome Mortgage Interest:  %,.0f\n"
                        + "\tHealth Insurance Tax Credit:  %,.0f\n\n"
                        + "Tax at 17%%:  $%,.0f\n"
                        + "Annual Income After Tax:  $%,.0f\n"
                        + "Monthly Income After Tax:  $%,.0f", grossAnnualIncome, annualTuition, annualCharity,
                           homeMortgage, healthCredit, taxOwed, annualAfterTaxes, monthlyAfterTaxes);
    
        }
    
        System.out.print( "\n\nDo you want to calculate taxes for someone else?  Enter 'Y' or 'N' ");
         response = input.nextLine().charAt(0);
    
        if( Character.toUpperCase(response) == 'N') {
            System.out.print( "Laters");
            outerLoop = false;
        }
    
    }
    
    System.exit(0);
    
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still having issues copying the part of one array to another. I
Having issues referencing $(this) from within a the nested ajax 'success' function... I know
Alright, I'm having some issues and I believe it's a CSS one. Here is
We're having an issue on one of our fairly large websites with spam bots.
I'm having an issue with one of my controller's AJAX functionality. Here's what I
Having an issue with traversing in jQuery.. hopfully an easy one..but I'm banging my
One of my users is having an issue when trying to open an Excel
I'm having an issue bending my head around this one. I have a table
I'm having issues with Unicode characters in Perl. When I receive data in from
I'm having a weird issue with my Silverlight 4 project, although it's one I've

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.