I need some help with solving this problem I was assigned. I have some errors right now and am wondering as to why they and how I can solve them. The problem from the book asks: Write a program the prompts the user to enter a social security number in the format of ddd-dd-ddd, where d is the digit.
line 7: You still want to initialize i to a value. If you start i at 0, I think you'd still want the - characters to be at positions 3 and 6. See also AbstractionAnon's above comment for line 14.
line 9: The code is using the assignment operator = instead of equality ==. See AbstractionAnon's comment in the post above for line 17 using single quotes '-' instead of double quotes "-".
line 13: Remove the ; at the end of the if condition. The ; terminates the if statement so the compiler thinks the else statement is unattached.
I'm not sure about the logic though. Do you really want an "invalid" or "valid" message to appear for each number in the SSN entered? Or did you mean to evaluate all the characters entered and just output a single invalid/valid message?
No I wanted to evaluate all the characters entered and just output a single invalid or valid message. How would I do that? Right now everything works, but it is outputting valid for every character and actually it won't even display invalid. It only displays valid even if I enter less than or more than 8 characters properly.
Move the return 0; outside your loop, otherwise the program will exit after the first iteration.
Your code will still print out every iteration. Move the output to outside the loop and depending on the state of isValid, output the corresponding string.
Okay I moved the output outside however, when I enter the following sequence: 23-23-5435, it outputs "Is an invalid social security number" 3 times instead of just once.