hi, im fairly new to programming, could any one help me with this:
Code:
#include <stdio.h>
#include <string.h>
#include <math.h>
char set_user[20];
char set_pass[20];
char user[20];
char pass[20];
char old_pass[20];
char new_pass[20];
char old_user[20];
char new_user[20];
char menu_choice[20];
char option_choice[20];
int strcmp( const char *str1, const char *str2 );
void print_options() {
printf("________________________________________\n");
printf("TYPE 'user' TO CHANGE YOUR USERNAME\n");
printf("TYPE 'pass' TO CHANGE YOUR PASSWORD\n");
printf("TYPE 'logout' TO LOGOUT\n");
printf("TYPE 'options' TO PRINT OPTIONS\n");
printf("________________________________________\n");
}
void change_pass(char *str1, char *str2, char *str3) {
printf("Old Password: ");
scanf("%s", str1);
printf("New Password: ");
scanf("%s", str2);
if (strcmp (str1, str3) == 0 ) {
str3 = str2;
printf("YOUR PASSWORD HAS NOW CHANGED\n");
}
else {
printf("INCORRECT OLD PASSWORD\n");
}
}
void change_user(char *str1, char *str2, char *str3) {
printf("Old Username: ");
scanf("%s", str1);
printf("New Username: ");
scanf("%s", str2);
if (strcmp (str1, str3) == 0 ) {
str3 = str2;
printf("YOUR USERNAME HAS NOW CHANGED FROM %s TO %s\n", str1, str2);
}
else {
printf("INCORRECT OLD USERNAME\n");
}
}
void print_first_options() {
printf("\n");
printf("MENU OPTIONS\n");
printf("_______________________________\n");
printf("TYPE 'register' TO REGISTER\n");
printf("TYPE 'login' TO LOGIN\n");
printf("TYPE 'users' TO SHOW USERS\n");
printf("TYPE 'options' TO PRINT OPTIONS\n");
printf("_______________________________\n");
}
main() {
int a = 3;
int b = 3;
printf("\n");
printf("WELCOME\n");
printf("\n");
while ((a, b) == 3 ) {
print_first_options();
printf("Menu choice: ");
scanf("%s", menu_choice);
if (strcmp (menu_choice, "register") == 0 ) {
printf("REGISTER\n");
printf("SET YOUR USERNAME\n");
printf("Username: ");
scanf("%s", set_user);
printf("SET YOUR PASSWORD\n");
printf("Password: ");
scanf("%s", set_pass);
printf("\n");
printf("YOURE NOW REGISTERED\n");
}
else if (strcmp (menu_choice, "login") == 0 ) {
printf("Username: ");
scanf("%s", user);
printf("Password: ");
scanf("%s", pass);
if (strcmp (user, set_user) != 0 || strcmp (pass, set_pass) != 0 ) {
printf("\n");
printf("USERNAME OR PASSWORD IS INCORRECT\n");
printf("YOU MAY NEED TO REGISTER\n");
printf("\n");
}
else {
while (strcmp (option_choice, "logout") != 0 ) {
printf("\n");
printf("WELCOME TO YOUR SYSTEM %s\n", user);
printf("\n");
print_options();
printf("Option choice: ");
scanf("%s", option_choice);
if (strcmp (option_choice, "options") == 0 ) {
print_options();
}
else if (strcmp (option_choice, "user") == 0 ) {
printf("\n");
printf("CURRENT USERNAME: %s\n", set_user);
printf("\n");
change_user(old_user, new_user, set_user);
}
else if (strcmp (option_choice, "pass") == 0 ) {
printf("\n");
printf("CURRENT PASSWORD: %s\n", set_pass);
printf("\n");
change_pass(old_pass, new_pass, set_pass);
}
else {
printf("\n");
printf("INCORRECT INPUT\n");
printf("\n");
}
}
printf("\n");
printf("YOUVE NOW LOGGED OUT\n");
printf("\n");
}
}
}
the problem is when i register and login its fine but when i logout then login again it logs out straight away because the option_choice variables value is always "logout", ive tried declaring option_ choice to a different value after the while option_choice is not equal to "logout" loop but it comes up with a error when i compile it.
Thanks.