I have 2 problems. One problem is the fact that in my for-loop I just used a constant, 3. This is fine for this specific program, though if I were to add more names in the future I would be required to correspondingly update the constant everytime. My first question then, is what should I use to represent the amount of items in the index at the 3 instead of just using a constant if possible.
My second problem is that I would like this program to only accept the names that I have placed in the name index. If the user inputs an incorrect name, I would just like it to print "Please input valid name" and then prompt the user for another string which will run through the original program of determining a names number.
This is my code feel free to leave your thoughts. Thank you!
long number[] = {8178895397, 8178895398, 8178895399};
string name[] = {"Jake", "Dylan", "Gabe"};
int main(void)
{
string in_name = get_string("name of person\n");
for(int i = 0; i < 3; i++)
{
if(strcmp(in_name, name[i]) == 0)
{
printf("%ld", number[i]);
{
printf("\n");
return true;
}
}
}
}