If choice is 1, user will be prompted to enter the month and then the person and salary earned.

Total number of person entered should not exceed 8.

An empty entry on the "Enter person" prompt should allow user to break out of the loop.


//i have been stuck on this part for the longest time and would really appreciate it if someone could help me. Thanks

Recommended Answers

All 5 Replies

booean doneEnteringData = false;

while (!doneEnteringData)
{
    String name;
    double salary;
    int month;

    // ask for name
    if (/* name is empty */)
        doneEnteringData = true;
    else    
    {
        // ask for month and salary and do whatever you do with it.
    }
}

thanks for your help. but what i'm really stuck at is what method should i use to break out of the loop when entering a maximum of 8 people income data. Etc: Hitting enter to break out of the loop if i just want to enter the income data for one person

thanks for your help. but what i'm really stuck at is what method should i use to break out of the loop when entering a maximum of 8 people income data. Etc: Hitting enter to break out of the loop if i just want to enter the income data for one person

Use break;

thanks for your help. but what i'm really stuck at is what method should i use to break out of the loop when entering a maximum of 8 people income data. Etc: Hitting enter to break out of the loop if i just want to enter the income data for one person

Use break;

Use break or change doneEnteringData to true. That gets you out of the loop. Add a condition to check the number of people entered and set doneEnteringData to true if that is >= 8.

here's how i would do it:

for (int pos=0; ;pos++)  {		
	if (pos == 8)  {
		//too many entries
		break;
	}

	/* make this into a function */				
	//ask for month
	String month = //get month from input;
	......
	......
		
	if (name.length() == 0)
		break;
	else {
		//print it or do whatever
	}
}
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.