I have to write a program that registers information about a n number of people, categorize them depending on how much they donated and finally outputs all the info to a txt file.
I found someone else doing something similar on this forum and im trying to analyze that code to do what i need but the objetive is not the same and im lost.
Right now the problem is that the program skips some of the necessary user inputs and then enters in a infinite loop.
Since you didn't increment the counter variable you had an infite loop. while (counter < contributors)
I quickly hacked together a little skeleton, maybe you want/can complete it.
I have a couple questions, i hope you can help/clarify me:
Im trying to do the part that verifies that the phone entered is a 10 digit number:
1 2 3 4 5 6 7 8 9 10 11
bool valid_phonenumber(string phone)
{
if (phone.length() != 10)
returnfalse;
for (auto x : phone) {
if (x >'9' || x <'0')
returnfalse;
}
returntrue;
That code, as is, works. It keeps asking for the correct input until it is entered.
However, if i add a cout << "Please enter a 10 digit number; before each return false it will enter in a loop and ask for a number indefinitely.
Why is this?
[This part is now solved] All needed to do was chnging the and operator(&&) for an or(||) one.
And also... the part that verifies that the amount donated does not seem to work while (con.amount < MIN_AMOUNT && con.amount > MAX_AMOUNT);
For some reason the && operator is not working there and is passing everything as true. It will work if I only leave one of the sided. Why is this happening?
And also... the part that verifies that the amount donated does not seem to work
while (con.amount < MIN_AMOUNT && con.amount > MAX_AMOUNT);
For some reason the && operator is not working there and is passing everything as true. It will work if I only leave one of the sided. Why is this happening?
Silly mistake of me - it must be while (con.amount < MIN_AMOUNT || con.amount > MAX_AMOUNT);