Hello everyone,

I am writing a simple program for homework that processes the users income taxes. Part of the assignment is to allow the user to process a second user if they desire.

My problem is that when the user elects to go ahead with round number two. The program skips the part of allowing the user to enter their name and goes right to the next output line. I believe in c++ something like cin.ignore would do the trick, but I have no idea what to do in Java. I cannot figure out how to use the reset command nor the clear function..

I have tried placing the variables in and out of the loop but nothing is working .. any help is GREATLY appreciated

Here is the output,,, code is kind of long to post on here ,, if anyone is willing to look at it Im more than happy to post ..

Please enter your first and last name: sdiksdi
Hello sdiksdi please enter the following information
and I will compute your Federal Income Tax.

Enter your salary income: 232

Enter your interest income: 2323

Enter the total number of exemptions withheld: 3

Enter the total amount of tax withheld: 233
Your refund amount is $1226.0
sdiksdi if you would like to process another tax payer please enter 1,
otherwise enter 0 to end this program:1
Please enter your first and last name: Hello please enter the following information
and I will compute your Federal Income Tax.

Enter your salary income:

Recommended Answers

All 2 Replies

Hello everyone,

I am writing a simple program for homework that processes the users income taxes. Part of the assignment is to allow the user to process a second user if they desire.

My problem is that when the user elects to go ahead with round number two. The program skips the part of allowing the user to enter their name and goes right to the next output line. I believe in c++ something like cin.ignore would do the trick, but I have no idea what to do in Java. I cannot figure out how to use the reset command nor the clear function..

I have tried placing the variables in and out of the loop but nothing is working .. any help is GREATLY appreciated

Here is the output,,, code is kind of long to post on here ,, if anyone is willing to look at it Im more than happy to post ..

Please enter your first and last name: sdiksdi
Hello sdiksdi please enter the following information
and I will compute your Federal Income Tax.

Enter your salary income: 232

Enter your interest income: 2323

Enter the total number of exemptions withheld: 3

Enter the total amount of tax withheld: 233
Your refund amount is $1226.0
sdiksdi if you would like to process another tax payer please enter 1,
otherwise enter 0 to end this program:1
Please enter your first and last name: Hello please enter the following information
and I will compute your Federal Income Tax.

Enter your salary income:

If you supplied some of the equations for calculating the refund amount I'd probably want to create the program for you...its a habit i have :P
Well you could try something like:

Scanner in = new Scanner(System.in);
	System.out.println("Please enter the following details. (If you want to end please type in 0) ");
	input.nextLine();
	
	while(!input.equals(0)){
                // System.out.println("Name and stuff here");
		// Code for tax calculations
		
		System.out.println("Would you like to have another go? If yes, please input the number 1. Otherwise input 0 to exit. ");
		in.nextLine();			//go to the next line.
		input = in.nextLine();
		
	}
	System.out.println("Thanks for that :P");

This is a rough code for it but as long as they don't enter the number zero it will keep looping through. Hope this helps abit.

If you supplied some of the equations for calculating the refund amount I'd probably want to create the program for you...its a habit i have :P
Well you could try something like:

Scanner in = new Scanner(System.in);
	System.out.println("Please enter the following details. (If you want to end please type in 0) ");
	input.nextLine();
	
	while(!input.equals(0)){
                // System.out.println("Name and stuff here");
		// Code for tax calculations
		
		System.out.println("Would you like to have another go? If yes, please input the number 1. Otherwise input 0 to exit. ");
		in.nextLine();			//go to the next line.
		input = in.nextLine();
		
	}
	System.out.println("Thanks for that :P");

This is a rough code for it but as long as they don't enter the number zero it will keep looping through. Hope this helps abit.

THank You very much for taking the time to write back ,,, Im ganna try to implement it now ..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.