When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
10 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
instead of having to do all the if statements I want it so the user inputs a name from the array and we pull the position from it
Figure out what is duplicated code, i.e. which lines are almost exactly the same.
In your case the 4 if clauses look exactly the same, with the only difference being the number which is n - 1 for the nth if case.
Also be aware that in your case num is always just a local variable inside each individual if body.
As if now you wouldn't be able to access the variable after the if-else/if chain has ended
for(int i=0; i<4; i++) { // Use a loop here to make sure it's within the max amount of users
if (strcmp(usernameinput, users[i]) == 0) {
num = i; // Store the position of the username in num
break; // Exit the loop when the username is found
something like this?
Try it, I'm currently taking a dump so even if I wanted to I wouldn't be able to test it for you rn
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity