for (int j=0;j<5;j++)
cout<<"\nPlease enter the four digit ID number: ";
cout<<"\nPlease enter the annual income: ";
cout<<"\nPlease enter the number of household members";
void Household::setID(string D)
while (D.length()!= 4)
cout<<"\nInvalid ID number! Must be 4 digits. Re-Enter ";
void Household::setIncome(float I)
cout<<"\nIncome must be greater than 0! Re-Enter ";
void Household::setMembers(int M)
cout<<"\nHousehold members must be greater than 0! Re-Enter ";
If the input for ID is invalid, it will first ask for the income and then the members and only thereafter ask to re enter a valid ID.
If ID and income was invalid, It will first ask for members to be entered, and only thereafter ask for valid inputs of ID and income.. and so forth.
Program acts very weird after.
How can I make it such that an input is requested straight after an incorrect input is entered.
p.p.s new to coding so if I did not use the correct terms or if any other problems you see please let me know.
Hope I explained my problem well.
Thanks for your reply it does make alot of sense and I understand your solution , though what the question states exactly is:
"Create a default constructor and an overloaded constructor that accepts the identification number, the annual income for the household and the number of household members. In the set methods, validate that the identification number is four digits, annual income must be positive and the number of household members can be >=0."
Doesn't this solution not validate it in the actual set method but rather in another method? Not really what they asking of me..