So I am very new to coding (literally started learning c a few days ago) and I decided to just play around and see if I can apply what I learned so far. I created an "employee search" program that prompts the user for a name and it will check to see if the employee exists. I ran into an issue within the loop; if I were to type "Chris" into the terminal and click enter, it'll say something like: "Employee not found." "Chris found." "Employee not found."How do I go about making the program confirm the name is within the "database" without it repeating the "error" message. Sorry for the newbie question. Again, I'm very new to this.
#include <cs50.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
// declare array
string employee[] = {"Damien", "Chris", "Emma"};
// print intro message and prompt user for name
printf("Welcome to employee search\n");
printf("Please input an employee name: ");
string name = get_string();
// here is where I run into the issue where it'll repeat "employee not found"
for(int i = 0; i < 3; i++)
{
if(strcmp(name, employee[i])==0)
{
printf("%s found\n", name);
}
else
{
printf("Employee not found\n");
}
}
}