I'm having problems with inputting accounts for each person (customer). Help? Haha. ^^
For each person, he may have up to three accounts. Inside the account, he has to input his account number and balance. Then when I view it, it has to display the number of accounts the person has.
You might be wondering why it has to input his account number and balance when it's just the number of accounts it displays. Haha! But this isn't really the whole project. The options are from A-I. As you can see, I just put A, B, H, and I.
Here's my code.
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdbool.h>
#define SIZE 10
#define MAX 3
typedef struct
{
char cID[7];
char first[30];
char last[20];
char midi;
char address[30];
char city[20];
}CUSINF;
typedef struct
{
char account[6];
int balance;
}CUSACC;
void getCusInf(CUSINF x[], int count);
void getCusAcc(CUSACC y[], CUSINF x[], int count);
void viewCus(CUSINF x[], CUSACC y[], int count);
int main(void)
{
CUSINF x[SIZE];
CUSACC y[MAX];
char choice;
int count=0, res;
char id[7];
do{
system("cls");
printf("\n[a] Add Customer Information");
printf("\n[b] Add Customer Account");
printf("\n[h] View All");
printf("\n[i] Quit");
printf("\n\nEnter Choice: ");
scanf(" %c", &choice);
switch(choice)
{
case 'a':
case 'A': system("cls");
getCusInf(x, count);
count=count+1;
break;
case 'b':
case 'B': getCusAcc(y, x, count);
count=count+1;
break;
case 'h':
case 'H': system("cls");
viewCus(x, y, count);
count=count+1;
break;
case 'i':
case 'I': printf("\n\nThank you for using this program!");
getch();
exit(0);
default: printf("\n\nInvalid Input! Try Again.\n\n");
getch();
break;
}
}while(choice!='i' || choice!='I');
getch();
}
void getCusInf(CUSINF x[], int count)
{
int i, res;
char id[7];
if(count<SIZE)
{
fflush(stdin);
printf("\nEnter Customer ID: ");
gets(id);
for(i=0;i<count;i++)
{
res=strcmp(x[i].cID, id);
if(res==0)
{
printf("ID already taken. Enter different ID.");
}
}
if(res!=0)
{
strcpy(x[i].cID, id);
printf("Enter First Name: ");
gets(x[count].first);
printf("Enter Last Name: ");
gets(x[count].last);
printf("Enter Middle Initial: ");
scanf(" %c", &x[count].midi);
fflush(stdin);
printf("Enter Address: ");
gets(x[count].address);
printf("Enter City: ");
gets(x[count].city);
}
}
else
printf("\nSorry you cannot add information anymore.");
getch();
}
void getCusAcc(CUSACC y[], CUSINF x[], int count)
{
int i, res;
char id[7];
fflush(stdin);
printf("\n\nEnter ID Number [xx-xxx]: ");
gets(id);
if(count<MAX)
{
for(i=0;i<count;i++)
{
res=strcmp(x[i].cID, id);
if(res==0)
{
printf("Enter Account Number: ");
gets(y[count].account);
printf("Enter Balance: ");
scanf("%d", &y[count].balance);
}
}
if(res!=0)
printf("\n\nNO RECORDS FOUND!");
}
else
printf("\nSorry you cannot add information anymore.");
getch();
system("cls");
}
void viewCus(CUSINF x[], CUSACC y[], int count)
{
int i=0;
fflush(stdin);
printf("Costumer Information\n\n");
for(i=0;i<count;i++)
{
fflush(stdin);
printf("Customer's ID: %s\n", x[i].cID);
printf("Customer's Name: %s %c. %s\n", x[i].first, x[i].midi, x[i].last);
printf("Customer's Address: %s\n", x[i].address);
printf("Customer's City: %s\n", x[i].city);
//PRINT Number of Accounts
printf("\n\n\n");
}
getch();
}
I'm also having problems with viewing all the info. Like, if it's the first time I view it, it's okay. But when I view it the second time around, third, etc., it displays trashes. I can't really explain it. :/
I'm trying to solve it, too. Hopefully you guys could help me, too. THANK YOU SO MUCH IN ADVANCE!! ^^