Why is the loop below not exiting on user input of \"-999\" after the second ite
ID: 3656688 • Letter: W
Question
Why is the loop below not exiting on user input of "-999" after the second iteration? for(input_ctr = 0; input_ctr < data_struct_sz; input_ctr++) { /* Begin collecting account information */ do { ok_to_proceed = 'T'; /* Collect account member's number */ printf (" Enter Client Number (1 - 1000; -999 to end): "); fflush (stdin); scanf ("%i", &data;[input_ctr].number); fflush (stdin); if (data[input_ctr].number != -999) { /* Validate the account numbers entered are within the acceptable range. If they are not within the acceptable range re-prompt. */ if (data[input_ctr].number < 1 || data[input_ctr].number > 1000) { printf (" *** Invalid entry. Account number must be greater "); printf ("than or equal to 1, less than or equal to 1000, or -999. "); printf ("to end. Please try again. *** "); ok_to_proceed = 'F'; } /* Ending if statement */ /* Validate the account numbers entered are unique. If they are not uniuque, re-prompt. */ for (unique_ctr = 0; unique_ctr < input_ctr; unique_ctr++) { if (data[input_ctr].number == data[unique_ctr].number) { printf(" *** Member account number already in use. Please "); printf("try again. *** "); ok_to_proceed = 'F'; } /* Ending if statement */ } /* Ending for loop */ } /* Ending if statement */ /* Validate the first account number entered is not the exit code. If it is the exit code, exit the program */ if (data[input_ctr].number == -999) { if (data[0].number == -999) { printf (" Thank you for using the Client Center. "); printf ("Have a nice day! "); return 1; } /* Ending if statement */ /* Validate the remaining numbers entered are not the exit code. If they are the exit code, exit the loop */ else { printf (" User has completed inputing data. Thank You. "); // ok_to_proceed = 'T'; break; } /* Ending else statement */ } /* Ending if statement */ } while (ok_to_proceed == 'F'); /* Ending do-while loop */Explanation / Answer
if (data[input_ctr].number == -999) //input check { if (data[0].number == -999) // data check { printf (" Thank you for using the Client Center. "); printf ("Have a nice day! "); return 1; } /* Ending if statement */ Note according to your code if both the condition satisfy only then return is executed write it as if (data[input_ctr].number == -999) { printf (" Thank you for using the Client Center. "); printf ("Have a nice day! "); return 1; } else if (data[0].number == -999) // data check { printf (" Thank you for using the Client Center. "); printf ("Have a nice day! "); return 1; }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.