Thank you VART;
My instructor has us doing files only so I cant use the debug feature in code blocks. Can you tell me where I can find out more about the debug features you listed in your comment? I have made several changes in my code now and almost everything works except that if you enter an incorrect ID or Password it should output "ID or Password is incorrect. Please try again." but it skips right over the else statement that does this. any suggestions.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void game_choice(void);
int main(void)
{
char mem_id [10][20], mem_passw [10][20];
char tempid[20], temppw[20];
int num_Mems = -1; // wrong
num_Mems=0;
int choice = 0;
int curr_user = 0;
int i, j, jj, k, kk, l, ll;
int login_mem_id = -1;
while(1) // while loop is better
{
printf("Start Program\n");
printf("1. Log in\n");
printf("2. Sign up\n");
printf("3. Exit\n");
printf("What do you want to do? \n\n");
//scanf("%i", &choice); // wrong placeholder
scanf("%d", &choice);
//switch (choice)
//{
//case 1:
if(choice==1)
{
printf("Please input user ID:");
scanf("%s", tempid);
getchar();
printf("Please input password:");
scanf("%s", temppw);
getchar();
for (i = 0; i < num_Mems; i++)
{
if (strcmp(tempid, mem_id[i]) == 0 && strcmp(temppw, mem_passw[i]) == 0)
{
printf("Welcome %s.\n",mem_id);
curr_user = i; // wrong
login_mem_id=i;
}
else if (strcmp(tempid, mem_id[i]) != 0 || strcmp(temppw, mem_passw[i]) != 0)
{
printf("ID or Password is incorrect. Please try again.");
}
break;
}
printf("Thank you!!!\n");
if (login_mem_id!=-1)
{
//game_choice(mem_id); // you don't know how to pass 2D char array yet. so implement game_choice procedure here not using function.
game_choice();
}
login_mem_id=-1;
}
//case 2:
else if(choice==2)
{
printf("Please input user ID:");
scanf("%s",mem_id[num_Mems]);
getchar();
printf("Please input password:");
scanf("%s",mem_passw[num_Mems]);
getchar();
printf("Thank you!!!");
num_Mems++;
}
//case 3:
//exit(0);
else if(choice==3)
{
break;
}
}
//}
return 0;
}
//void game_choice(int mem_id) // mem_id is not integer
void game_choice()
{
//int choice = 0;
while (1)
{
int choice = 0;
printf("1. Rock, paper, scissor game\n");
printf("2. Blackjack game\n");
printf("3. Log out\n");
printf("What do you want to do?");
scanf("%d", &choice);
if (choice ==1)
{
printf("That game is not available at this time.\n");
break;
}
if (choice == 2)
{
printf("That game is not available at this time.\n");
break;
}
if (choice == 3)
{
return 0;
}
// switch (choice) // do not use switch
// {
// case 1:
// case 2:
//case 3:
// printf("Good Bye %s", mem_id); // mem_id is integer
// return 0;
// }
}
}
Thank you.