Limit on check writing

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.

Any help would be appreciated.

//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;
   std::cout << "You have " << max_checks_for_month - current_checks_written_in_this_month << " checks left for this month" << std::endl;
// code below... 
@eraggo Can you tell me why i am still receiving an error. The remaining checks is giving me 858993466

Last edited on
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?

Last edited on
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?
Last edited on
Topic archived. No new replies allowed.