I am trying to make a bank program. I am required to limit the amount of checks someone can write in a month. The number of checks the person can write in a month is 6. I am trying to write an if statement to display an error message if they have ran out of checks for that month. How can I do this? I also want to tell print out how many checks they may have remaining if they did not reach the maximum number of checks for the month.
//Code above.. making limits, setting current checks for month, calculating current checks written on this month etc.
if (current_checks_written_in_this_month>6)
std::cout << "ERROR" << std::endl;
else
std::cout << "You have " << max_checks_for_month - current_checks_written_in_this_month << " checks left for this month" << std::endl;
// code below...
Given the code you've posted, you only declare a variable CheckRemaining as a local variable to the writeCheck() function. Thus, when you callint in the printIt() function, you get garbage data for that variable. I'm just guessing you'll need to add a CheckRemaining variable to your header file for your class and then make sure you initialize it with a value.
When I initialize CheckingRemaining =0 in the header file i get an "Error:data member initializer is not allowed". The error is showing up under the equal sign. Why is this?
I would initialize it in your setCheckLimit() function, and I think you want it to be 6, not 0. Then, you'll have to work on your logic in your writeCheck() function. First, you have to get rid of the local CheckRemaining variable. Then, you'll have to check if CheckRemaining is > 0 before you write the check.
edit... Why did you make those three variables protected and not private?