Code:
/* Leslie Bauert
CSE1311 HW 8
Aug. 11, 2014
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Members
{
char fName[20];
char lName[20];
char Email[30];
char id[20];
char pass[20];
char SSN[15];
char gender;
double GPA;
int age;
};
void Up_Date_Info(struct Members mem[20],int i);
void View_Info (struct Members mem[20], int i);
void display();
int main()
{
int i;
struct Members mem[20];
for(i = 0; i < 20; i++)
{
strcpy(mem[i].id, " ");
strcpy(mem[i].pass, " ");
strcpy(mem[i].Email, " ");
strcpy(mem[i].fName, " ");
strcpy(mem[i].lName, " ");
strcpy(mem[i].SSN, " ");
//char gender = '\0';
}
char choice;
char temp[20];
char temppass[20] = "";
i = 0;
printf("Start Program\n");
printf("1. Log in\n");
printf("2. Sign up\n");
printf("3. Exit\n");
do
{
printf("What do you want to do: ");
scanf("%c", &choice);
printf("\n");
switch (choice)
{
case '1':
printf("Please enter your id: ");
strcpy(temp, "");
scanf("%s", temp);
printf("Please enter your password: ");
strcpy(temppass, "");
scanf("%s", temppass);
getchar();
for (i = 0; i < 20; i++)
{
if (strcmp(temp, mem[i].id) != 0 || strcmp(temppass, mem[i].pass) != 0)
{
while ((strcmp(temp, mem[i].id) != 0 || strcmp(temppass, mem[i].pass) != 0))
{
if (strcmp(temp, mem[i].id) != 0)
{
printf("Please re-enter your id: ");
strcpy(temp, "");
scanf("%s", temp);
}
if (strcmp(temppass, mem[i].pass) != 0)
{
printf("Please re-enter your password: ");
strcpy(temppass, "");
scanf("%s", temppass);
getchar();
}
}
printf("\n");
}
if (strcmp(temp, mem[i].id) == 0 && strcmp(temppass, mem[i].pass) == 0)
{
printf("Hello %s!!!\n\n", mem[i].id);
do
{
printf("1. View User Account\n");
printf("2. Update User Account\n");
printf("3. Log out\n\n");
printf("What do you want to do?");
choice = '\0';
scanf("%c", &choice);
getchar();
switch (choice)
{
case '1':
printf("User id is: %s\n", mem[i].id);
printf("User password is: %s\n", mem[i].pass);
printf("Your first name is %s\n", mem[i].fName);
printf("Your last name is %s\n", mem[i].lName);
printf("Your Email is %s\n", mem[i].Email);
printf("Your GPA is %.1f\n", mem[i].GPA);
printf("Your gender is %c\n", mem[i].gender);
printf("Your age is %d\n", mem[i].age);
printf("Your SSN is %s\n", mem[i].SSN);
printf("\n");
break;
case '2':
Up_Date_Info(mem, i);
getchar();
break;
case '3':
break;
default:
printf("That is not a valid option at this time\n");
break;
}
}while (choice != '3');
}
display();
break;
}
break;
case '2':
printf("Please input user id: ");
scanf("%s", temp);
for(i = 0; i < 20; i++){
if(strcmp(" ", mem[i].id) == 0)
{
strcpy(mem[i].id, temp);
printf("Please input user password: ");
strcpy(temp, "");
scanf("%s", temp);
strcpy(mem[i].pass, temp);
printf("Please input Email: ");
strcpy(temp, "");
scanf("%s", temp);
strcpy(mem[i].Email, temp);
printf("Please input GPA: ");
strcpy(temp, "");
scanf("%s", temp);
mem[i].GPA = atof(temp);
printf("Please input first name: ");
strcpy(temp, "");
scanf("%s", temp);
strcpy(mem[i].fName, temp);
printf("Please input last name: ");
strcpy(temp, " ");
scanf("%s", temp);
strcpy(mem[i].lName, temp);
printf("Please input gender: ");
strcpy(temp, " ");
scanf("%s", temp[i]);
strcpy(mem[i].gender, temp[i]);
printf("Please input age: ");
strcpy(temp," ");
scanf("%s", temp);
mem[i].age = atoi(temp);
printf("Please input SSN: ");
strcpy(temp, "");
scanf("%s", temp);
strcpy(mem[i].SSN, temp);
printf("Thank you!!!\n\n");
display();
break;
}
}
break;
case '3':
break;
default:
printf("%c is not a viable option at this time\n", choice);
break;
}
}while(choice != '3');
printf("Goodbye %s!!!\n", mem[i].id );
}
void display()
{
printf("1. Log in\n");
printf("2. Sign up\n");
printf("3. Exit\n\n");
}
void Up_Date_Info(struct Members mem[20], int i)
{
char choice = '\0';
char temp[20];
printf("1. ID\n");
printf("2. PASSWORD\n");
printf("3. FIRST NAME\n");
printf("4. LAST NAME\n");
printf("5. EMAIL\n");
printf("6. GPA\n");
printf("7. GENDER\n");
printf("8. AGE\n");
printf("9. SSN\n");
printf("What do you want to update?");
scanf("%s", &choice);
switch(choice)
{
case '1':
printf("Please input your new ID: \n");
strcpy(temp," ");
scanf("%s", temp);
strcpy(mem[i].id, temp);
printf("Your new id is %s\n", mem[i].id);
printf("Update is done!!!\n");
break;
case '2':
printf("Please enter your new password:");
strcpy(temp," ");
scanf("%s", temp);
strcpy(mem[i].pass, temp);
printf("Your new password is %s\n", mem[i].pass);
printf("Update is done!!!\n");
break;
case '3':
printf("Please enter your new first name:");
strcpy(temp," ");
scanf("%s", temp);
strcpy(mem[i].fName, temp);
printf("Your new first name is %s\n", mem[i].fName);
printf("Update is done!!!\n");
break;
case '4':
printf("Please enter your new last name:");
strcpy(temp," ");
scanf("%s", temp);
strcpy(mem[i].lName, temp);
printf("Your new last name is %s\n", mem[i].lName);
printf("Update is done!!!\n");
break;
case '5':
printf("Please enter your new Email:");
strcpy(temp," ");
getchar();
scanf("%s", temp);
strcpy(mem[i].Email, temp);
printf("Your new Email is %s\n", mem[i].Email);
printf("Update is done!!!\n");
break;
case '6':
printf("Please enter your new GPA:");
strcpy(temp," ");
scanf("%s", temp);
mem[i].GPA = atof(temp);
printf("Your new GPA is %f\n", mem[i].GPA);
printf("Update is done!!!\n");
break;
case '7':
printf("Please enter your new gender:");
strcpy(temp," ");
scanf("%c", temp[i]);
mem[i].gender = temp[i];
printf("Your new gender is %c\n", mem[i].gender);
printf("Update is done!!!\n");
break;
case '8':
printf("Please enter your new age:");
strcpy(temp," ");
scanf("%s", temp);
mem[i].age = atoi(temp);
printf("Your new age is %d\n", mem[i].age);
printf("Update is done!!!\n");
break;
case '9':
printf("Please enter your new SSN:");
strcpy(temp," ");
scanf("%s", temp);
strcpy(mem[i].SSN, temp);
printf("Your new SSN is %s\n", mem[i].SSN);
printf("Update is done!!!\n");
break;
default:
printf("%c is not a valid option at this time.", choice);
break;
}
}
/*
C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'main':|
C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|116|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|177|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|178|warning: passing argument 1 of 'strcpy' makes pointer from integer without a cast [enabled by default]|
c:\program files (x86)\codeblocks\mingw\include\string.h|45|note: expected 'char *' but argument is of type 'char'|
C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|178|warning: passing argument 2 of 'strcpy' makes pointer from integer without a cast [enabled by default]|
c:\program files (x86)\codeblocks\mingw\include\string.h|45|note: expected 'const char *' but argument is of type 'char'|
C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'Up_Date_Info':|
C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|291|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'double' [-Wformat=]|
C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|301|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|311|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'main':|
C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|204|warning: control reaches end of non-void function [-Wreturn-type]|
||=== Build finished: 0 error(s), 8 warning(s) (0 minute(s), 0 second(s)) ===|
*/
Warnings: