Write a C program implement a simple database. Your program will provide text-based menus for a user
interface. Create a “polling loop” to display a menu and prompt for user input. Switch inside the loop out
to various functions.
Keep track of a list of employees (first and last names) and their corresponding salaries. Store your data
in three arrays, one array for the first name, one array for the last name, and one array for the salary. The
program must allow addition of an employee, deletion of an employee, screen printout of the entire
employee list, modification of an employees salary, and saving of all records to a text file.
Now this is what i have done so far. My add function works, and my List function works as well, but the list function malfunctions a little bit and i cant find out why. It lists the names and salary's, but prints a bunch of black lines underneath. There is something going wrong. My Modify and delete functions work, but only for the first input, and i cant seem to modify or delete the second or third employee info. I am close, i just need a little help. Thanks.
Hi I saw your post while working on my own code and by the looks of it Im guessing your also in cisp 360 with Prof Ross. Heres my code , it works but not perfect. I hope it helps,
If you are in my class and would like to help each other in the future , my name is Jason I always sit in the front row always wear blue New England Patriots hat.
BTW the comments on Add() are Prof Ross , he helped me figure out what I was doing wrong.
-Good Luck
void printmenu()
{
printf("\n\ nWelcome to database 1.0\n");
printf("\n Please choose from the following menu options.\n");
printf("\n (A)dd, (D)elete, (M)odify, (L)ist, (S)ave, (Q)uit\n\n");
}
void add()
{
int row = 0;
char buf[30];
// find first blank spot
while (lname[row][0] != 0)
row++;
// prompt user for input
printf("\n\nPlease enter last name: ");
// read user input into a buffer
scanf("%s", buf);
// copy the buffer to the lnames array
strcpy(lname[row], buf);
// prompt user for input
printf("\nPlease enter first name: ");
// read user input into a buffer
scanf("%s", buf);
// copy the buffer to the lnames array
strcpy(fname[row], buf);
// prompt user for input
printf("\nPlease enter salary: ");
// read user and write it to sal array in the same statement
scanf("%lfs", &sal[row]);
void del()
{
char buf[30];
printf("\nPlease Enter Last name: ");
gets(buf);
for (int row = 0; row < MAX; row++)
{
if (!strcmp(buf, lname[row]))
lname[row][0] = 0;
}printmenu();
}
void modify()
{
char buf[30];
gets(buf);
int row = 0;
printf("\n\nPlease Enter Last name: ");
scanf("%s", buf);
if (strcmp(buf, lname[row]))
row++;
else;
printf("Please enter new salary: ");
scanf("%lfs", &sal[row]);
printf("\nYou have succesfully modified this entry");
printf("\n\***************************************************");
haha, yea im in that class. Thanks a lot for the reply man, it seems that i didnt have my add () function right and that was messing up my entire code. I was just about to email the teacher and ask him for help, your a life saver