Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Suppose an employee earns $2,200 per week and withdraw the following percentage (%) of his monthly
income from his/her account:
• Withdraw 60% monthly income for months having 31 days.
• Withdraw 50% monthly income for months having 30% days.
• Withdraw 80% monthly income for any other month in a year.
Find and display what percent (%) of his annual income is still available in his saving account at the end of
the year. If the amount in his account is more than 40% of his annual income than increase the balance
by 7% which is the annual interest rate and display the balance in the account otherwise simply display
the balance without including the interest.

What I have tried:

Tried to solve but couldn't make logic. this is not anywhere on google too :(
Posted
Updated 17-Oct-21 7:19am

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
You will not find a solution to exactly this problem on the internet: it's invented by your teacher to give you a chance to learn how to think about development, and practice it.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Comments
Hamza Jameel 17-Oct-21 11:11am    
Thanks I will keep in mind.
P.S it's for my grades
The approach I would take is write a function to calculate deductions for every month. To do it right, you will also need to determine how many days each month has. This is fairly simple except for the wrinkle that leap years cause. You can find this code on the internet so I might as well show you how this could look.
C++
bool IsLeapYear( int year )
{
    if( year % 4 )
        return false;   // nope, not divisible by 4
    if( year % 100 )
        return true;    // yes, not divisible by 100
    if( year % 400 )
        return false;   // nope, not divisible by 400

    return true;        // yes, year is a multiple of 400
}


int GetDaysInMonth(		// returns number of days in month
		  int year		// year number, 2021 right now
		, int month		// zero-based month so January is 0
		)
{
	const int monthsInYear = 12;
	const int daysInMonth[ monthsInYear ] =
	{
		  31	// january
		, 28	// february
		, 31	// march
		, 30	// april
		, 31	// may
		, 30	// june
		, 31	// july
		, 31	// august
		, 30	// september
		, 31	// october
		, 30	// november
		, 31	// december
	};

	if( ( month < 0 ) || ( month >= monthsInYear ) )
		return 0;		// idiot check

	bool isLeap = IsLeapYear( year );
	int number = daysInMonth[ month ];
	if( isLeap && ( month == 1 ) )
		++number;		// february of a leap year has an extra day
	return number;
}
Given this, for a given year you determine how many days are in each month.

The next thing you need to do is implement an account manager. It needs to have a starting date and an initial balance. Let's say you start at January 1st of this year and the account has $200 in it. Write a function to determine the end-of-month balance of the account. You will find that last January had 31 days in it by calling the function listed. Next determine how much the monthly income was. Then apply the deduction rules stated and you will have the balance. Make a loop and you should be able to do this for every month following of the entire year or any time duration you care to examine.

If I were you, I would also make one function to determine the income and another to determine the deductions for a given month and year. You aren't likely to find all of this on google and it is for the best that you don't. You are supposed to learn something and lifting a bunch of code from somewhere else does not teach one very much. This day-date stuff I showed you can be found many places and is this just one of many different ways it can be done.
 
Share this answer
 
v2
Comments
merano99 18-Oct-21 17:16pm    
Instead of doing an idiot check, it might be better to use data types that avoid this.

typedef enum TYP_MONTH {M_JANUARY, M_FEBRUARY, M_MARCH, M_APRIL, M_MAY,
M_JUNE, M_JULY, M_AUGUST, M_SEPTEMBER, M_OCTOBER, M_NOVEMBER, M_DECEMBER};

int GetDaysInMonth( int year, TYP_MONTH month);
Quote:
Tried to solve but couldn't make logic. this is not anywhere on google too

You can't just come out with nothing.
You need to learn how to split your requirement in many smaller problems easier to solve and that you put together later.
- work out the logic of number of days of months in year.
- work out the logic of income for every month in year.
- calculate account incomes and withdraws.
And so on

For specific help, show your work and describe your problem.

By the way: solving the problem by hand is a good way to work out an algorithm.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900