#include<alloc.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<dos.h>
#include<ctype.h>
typedef struct node
{
int dd,mm,yy;
int cus_ac_no[15];
char cus_name[25],cus_add[45],cus_ph_no[17];
double cus_bal;
float cus_intrst;
struct node *next;
}node;
node *L,*ptr;
void add()
{
node *p,*q,*new;
p=q=L;
clrscr();
new=(node*)malloc(sizeof(node));
if(new==NULL)
{
printf("list is full");
getch();
return;
}
else {
printf(" Enter customer account number : ");
scanf("%d",new->cus_ac_no);
printf(" Enter customer name : ");
gets(new->cus_name);
printf(" Enter customer address : ");
gets(new->cus_add);
printf(" Enter customer phone number :");
gets(new->cus_ph_no);
printf(" Enter the amount you want deposit :");
scanf("%lf",&new->cus_bal);
while(new->cus_ac_no > p->cus_ac_no && p!=NULL)
{
q=p;
p=p->next;
}
if(L!=NULL){
q->next=new;
new->next=p;
}
else{
L=new;
new->next=p;
}
}
}
void list()
{
node *ptr;
ptr=L;
while(ptr!=NULL);
{
gotoxy(8,2); printf("============================================\n");
gotoxy(8,3); printf("......Customer's Information .......");
gotoxy(8,4); printf("============================================\n");
gotoxy(7,7); printf("|-> Customer Account number is: %d",ptr->cus_ac_no);
gotoxy(7,10); printf("|-> Customer Name is: %s",ptr->cus_name);
gotoxy(7,13); printf("|-> Customer Address is: %s",ptr->cus_add);
gotoxy(7,16); printf("|->Customer Phone number is: %s",ptr->cus_ph_no);
gotoxy(7,19); printf("|-> Customer Balence is : %.3lf ",ptr->cus_bal);
gotoxy(7,22); printf("|->Account opened on :");
gotoxy(7,24); printf("<-->Press any key to continue");
ptr=ptr->next;
} getch();
}
void transac()
{
printf("trans..");
getch();
}
void del(int cus_ac_no)
{
node *p,*q;
p=q=L;
while(cus_ac_no!=p->cus_ac_no && p!=NULL)
{
q=p;
p=p->next;
}
if(p==NULL){
printf("record not found");
getch();
return;
}
else{
if(L==p)
L=p->next;
else
q->next=p->next;
free(p);
}
}
int menu()
{ int i,s=0;
do{
clrscr();
gotoxy(4,9); printf("1.-> Adding a new Account\n");
gotoxy(4,12); printf("2.-> List all Accounts\n");
gotoxy(4,15); printf("3.-> Transaction [Deposit/Withdraw]\n");
gotoxy(4,18); printf("4.-> Delete any \n");
gotoxy(4,21); printf("5.-> Exit \n");
gotoxy(4,29); printf("Enter your choice [1-5] :");
scanf("%d",&s);
}while(s<1 && s>5);
return(s);
}
main()
{
int i;
int cus_ac_no[15];
while(1){
i=menu();
switch(i)
{
case 1 :
clrscr();
add();
break;
case 2:
clrscr();
list();
break;
case 3:
clrscr();
transac();
break;
case 4 :
clrscr();
printf("enter accnt no. that u want 2 erase:");
scanf("%d",cus_ac_no);
for(i=0;i<45;i++);
while(cus_ac_no[i] > '0 ' && cus_ac_no[i] <'9')
cus_ac_no[i]=cus_ac_no[i];
del(cus_ac_no[45]);
break;
case 5:
clrscr();
printf("THANK YOU FOR USING THIS SOFTWARE");
getch();
exit(0);
break;
default :
clrscr();
gotoxy(5,3); printf(" SORRY WRONG CHOICE....");
gotoxy(5,5); printf(" PRESS ANY KEY TO CONTINUE....");
getch();
break;
}
}
}
comp_sci11 0 Light Poster
WolfPack 491 Posting Virtuoso Team Colleague
What is the problem? We don't have the time to run and debug your program. Narrow down the function that is wrong and post it. Post properly formatted code.
comp_sci11 0 Light Poster
help!! my program is running but when i choose 2 which is the list function that display all the info. inputted by the user, it doesn't display at all!! and when i'm adding an account it is getting the acount number first and it will skip in getting the customer name and proceed to customer address.
Can someone help me?? pls..
And another problem,when i'm inputting a letter or words in the menu
it doesn't goes back again to accept another choice.unlike when i'm inputting a number greater than and less than my choices(1-5) it goes back again to accept another choice!can someone helpme pls!! I REALLY NEED TO RUN THIS PROGRAM!!
Eddy Dean 13 Junior Poster in Training
It might sound harsh, but we're (at least, Me) are not interested in how urgent this is for you.
Next time you post please use proper English, punctuation etcetera. Also choosing a proper title would help a lot. The title you used doesn't give any information at all. You're not giving any information about what the problem is.
The only thing you do is giving us a piece of code, without even telling what's wrong, and then expecting us to locate the problem and solve it.
I know it might not be your fault that your English isn't perfect, but I think punctuation is the same in all languages (Okay, most of the languages).
Don't think I'm mad at you, or dislike you. It's just several things that need to be corrected before you should expect to receive any usefull input from us.
I'll give you just an example to show how confusing it can be to read something without punctuation:
it doesn't goes back again to accept another choice.unlike when i'm inputting a number greater than and less than my choices(1-5) it goes back again to accept another choice
Now please re-read this sentence, and see if you can figure out what you mean with that. I can't really. I have no clue what you're trying to say in that sentence.
Yours,
Eddy
Rashakil Fol commented: You're awesome. +3
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
#include<alloc.h> #include<stdio.h> #include<string.h> #include<conio.h> #include<dos.h> #include<ctype.h> typedef struct node { int dd,mm,yy; int cus_ac_no[15]; char cus_name[25],cus_add[45],cus_ph_no[17]; double cus_bal; float cus_intrst; struct node *next; }node; node *L,*ptr; void add() { node *p,*q,*new; // new is a keyword which cant be used as a //varible . better choose a new name p=q=L; clrscr(); new[/COLOR]=(node*)malloc(sizeof(node)); if(new==NULL) { printf("list is full"); getch(); return; } else { printf(" Enter customer account number : "); scanf("%d",new->cus_ac_no); printf(" Enter customer name : "); gets(new->cus_name);[/COLOR] printf(" Enter customer address : "); gets(new->cus_add); printf(" Enter customer phone number :"); gets(new->cus_ph_no); printf(" Enter the amount you want deposit :"); scanf("%lf",&new->cus_bal); while(new->cus_ac_no > p->cus_ac_no && p!=NULL) { q=p; p=p->next; } if(L!=NULL){ q->next=new; new->next=p; } else{ L=new; new->next=p; } } } void list() { node *ptr; ptr=L; while(ptr!=NULL); { gotoxy(8,2); printf("============================================\n"); gotoxy(8,3); printf("......Customer's Information ......."); gotoxy(8,4); printf("============================================\n"); gotoxy(7,7); printf("|-> Customer Account number is: %d",ptr->cus_ac_no); gotoxy(7,10); printf("|-> Customer Name is: %s",ptr->cus_name); gotoxy(7,13); printf("|-> Customer Address is: %s",ptr->cus_add); gotoxy(7,16); printf("|->Customer Phone number is: %s",ptr->cus_ph_no); gotoxy(7,19); printf("|-> Customer Balence is : %.3lf ",ptr->cus_bal); gotoxy(7,22); printf("|->Account opened on :"); gotoxy(7,24); printf("<-->Press any key to continue"); ptr=ptr->next; } getch(); } void transac() { printf("trans.."); getch(); } void del(int cus_ac_no) { node *p,*q; p=q=L; // here cus_ac_no member of struct which is actually a array of // integer is compared with a integer value which is cus_acc_no which // accounts to the comparision of an int with pointer type ? while(cus_ac_no!=p->cus_ac_no && p!=NULL) { q=p; p=p->next; } if(p==NULL){ printf("record not found"); getch(); return; } else{ if(L==p) L=p->next; else q->next=p->next; free(p); } } int menu() { int i,s=0; do{ clrscr(); gotoxy(4,9); printf("1.-> Adding a new Account\n"); gotoxy(4,12); printf("2.-> List all Accounts\n"); gotoxy(4,15); printf("3.-> Transaction [Deposit/Withdraw]\n"); gotoxy(4,18); printf("4.-> Delete any \n"); gotoxy(4,21); printf("5.-> Exit \n"); gotoxy(4,29); printf("Enter your choice [1-5] :"); scanf("%d",&s); }while(s<1 && s>5); return(s); } main() { int i; int cus_ac_no[15]; while(1){ i=menu(); switch(i) { case 1 : clrscr(); add(); break; case 2: clrscr(); list(); break; case 3: clrscr(); transac(); break; case 4 : clrscr(); printf("enter accnt no. that u want 2 erase:"); scanf("%d",cus_ac_no); for(i=0;i<45;i++); // dont put quotes around the literals since now they will be treated // as characters and you actuallly want to compare integer values. while(cus_ac_no[i] > '0 ' && cus_ac_no[i] <'9') cus_ac_no[i]=cus_ac_no[i]; del(cus_ac_no[45]); break; case 5: clrscr(); printf("THANK YOU FOR USING THIS SOFTWARE"); getch(); exit(0); break; default : clrscr(); gotoxy(5,3); printf(" SORRY WRONG CHOICE...."); gotoxy(5,5); printf(" PRESS ANY KEY TO CONTINUE...."); getch(); break; } } }
Actually too many problems with your code.
I would list some of them and expect you to correct them to get any further help from our side. The problem areas in your code are marked as red.
Dont ever use
gotoxy ()
ever. I think that you are probably usign Turbo C++ compiler so better dump it and get a new compiler, the link of which is mentioned in one of the stickes. Usinggotoxy ()
kills program portability and you is considered as bad programming practice.The same goes with
getch ()
. Using it to make your program wait for input is bad since it is a non standard function. Better usegetchar ()
which performs the same function and is a portable one.Why do you need to keep the
cust_acc_no
in your structure to be an array of 15 ints. Cant it just be an int to hold the value of account number of a single customer ?Using
gets
afterscanf
is the worst mistake you can afford to do since thenewline character ('\n')
left afterscanf
would be accepted bygets
as a valid input thereby making the program not wait for the customer name input and always keeping the customer name as a newline character. Better usefgets (char*, size_t inputsize, filestream )
to get all the inputs from user. THe bottom line is either usefgets ()
orscanf ()
throughout your code and try not to intermingle them.The same advice of portability goes for
clrscr ()
as it is non standard function. dont use it.
Hope you make the following changes and present the code in a more appealign manner which will make it easier for us to find errors for you.
Hope it helped, bye.
Edited by TrustyTony because: fixed formating
Salem 5,199 Posting Sage
> new is a keyword which cant be used as a variable
True, but this is C, so it's OK.
There's some good stuff in there ~s.o.s~
Here's some more for the OP to think about.
> while(new->cus_ac_no > p->cus_ac_no
You're comparing two pointers here, not two values.
In general, you seem very confused as to what the customer account number is supposed to be. In places, it's an integer, and in other places, you seem to be trying to treat it as a string.
> while(ptr!=NULL);
That ; at the end is one place where your code can lock up.
If ptr is not NULL when it enters the loop, then that is where it will stay, because the loop body ( just that ; ) can't change the value of ptr.
The body of code which follows, which seems like it should be part of the while loop isn't part of the loop at all.
> for(i=0;i<45;i++);
This is another useless loop, which is just the same as saying
i = 45;
> while(cus_ac_no > '0 ' && cus_ac_no <'9')
i is now 45, but your array is only 15 elements. You're in no man's land doing who knows what to someone elses memory.
> cus_ac_no=cus_ac_no;
This isn't going to change i either, so if the while loop starts off being true, then this is where it will stay, forever assigning cus_ac_no[45] = cus_ac_no[45];
> del(cus_ac_no[45]);
More out of range access on the array with only 15 elements.
> scanf("%d",cus_ac_no);
If it were %s, and cus_ac_no were a char array (not an int array), this might make a bit of sense with the for loop which follows.
> clrscr(); and gotoxy(5,3);
You should remove ALL these until the program is working properly.
Until then, it's just clutter for everyone else to look at, and severely restricts people from trying your code for themselves.
When it's all working, adding them all in again won't take that long, as it's just tidying up the presentation, it's not going to affect the core functions at all.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.