You are on page 1of 4

#include<stdio.h> #include<conio.h> #include<string.

h> struct inventory{ char name[20]; int quantity; int quantity2; int price; }; main() { struct inventory item[100]; int i, j, b, a=0, c, d, e, f, g, k, h=0, p1=0, p2=0, p3=0, p4=0, total=0; char pw[15]="omi", pwtemp[15], pwtemp1[15], pwtemp2[15], search[20], sell[20]; password: printf("Enter password:"); scanf("%s", & pwtemp); if(strcmp(pw,pwtemp)!=0) { printf("Invalid Password.\nIf you want to enter again press 1.\nIf you want to exit press 2.\n"); scanf("%d", & d); if(d==1) { goto password; } else if(d==2) { exit(0); } } else if(strcmp(pw,pwtemp)==0) { goto main; } main: { printf("Enter the number of items:"); scanf("%d", &a); if(a==0) goto redo; printf("1.\n"); printf("Enter name of the item:"); scanf("%s",& item[0].name); printf("Enter quantity:"); scanf("%d", & item[0].quantity); printf("Enter price:"); scanf("%d",& item[0].price); for(i=1; i<a; i++) { printf("%d.\n", i+1); printf("Enter name of the item:"); scanf("%s",& item[i].name); printf("Enter quantity:"); scanf("%d", & item[i].quantity); printf("Enter price:");

} redo:

scanf("%d",& item[i].price); for(j=1; j<=i; j++) { if(strcmp(item[i].name,item[i-j].name)==0) { printf("product already exists.\n"); printf("Enter name of the item:"); scanf("%s",& item[i].name); printf("Enter quantity:"); scanf("%d", & item[i].quantity); printf("Enter price:"); scanf("%d",& item[i].price); j=0; } }

printf("What do you want to do?\n1.Sell items.\n2.Change inventory.\n3.Change password.\n4.Exit.\n5.Print report.\n6.Enter new products to invetory.\n"); printf("Enter your choice:"); scanf("%d",& b); if(b==3) { password3: printf("Enter new password:"); scanf("%s", & pwtemp1); for(k=0 ; k<strlen(pwtemp1) ; k++) { if(isupper(pwtemp1[k])) p1=1; if(islower(pwtemp1[k])) p2=1; if(isdigit(pwtemp1[k])) p3=1; if(pwtemp1[k]>32 && pwtemp1[k]<48) p4=1; } if(p1==0 || p2==0 || p3==0 || p4==0 || strlen(pwtemp1)<8) { printf("Invalid Password.\nThe password must contain lower case letters, upper case letters, digits and special letters.\nTo enter again press 1."); scanf("%d", & g); if(g==1) { goto password3; } } password2: printf("Re-enter your password:"); scanf("%s", & pwtemp2); if(strcmp(pwtemp1,pwtemp2)==0) { strcpy(pw,pwtemp1); printf("Successful.\n"); } else { printf("Password doesn't match.\nPress 1 to re-enter again.");

} } else if(b==2) { printf("Enter the name of the item you want to search:"); scanf("%s", & search); for(i=0; i<a; i++) { if(strcmp(item[i].name,search)==0) { printf("Enter the new quantity:"); scanf("%d", & item[i].quantity2); printf("Successful.\n\n"); item[i].quantity=item[i].quantity2; break; } else if(strcmp(item[i].name,search)!=0) { continue; } } if(i==a) printf("Item not in the inventory.\n\n"); } else if(b==1) { printf("Enter the name of the item you want to sell:"); scanf("%s", & sell); for(i=0; i<a; i++) { if(strcmp(item[i].name,sell)==0) { printf("Enter the quantity of the item sold:"); scanf("%d", & c); if(c>item[i].quantity) { printf("You don't have that much item.\n"); break; } item[i].quantity=item[i].quantity-c; break; } else if(strcmp(item[i].name,sell)!=0) continue; } if(i==a) printf("Item not in the inventory\n"); } else if(b==4) { exit(0); } else if(b==5) {

scanf("%d", & e); if(e==1) { goto password2; }

printf("No.\tName\tQuantity\tPrice\n"); for(i=0 ; i<a ; i++) { printf("%d.\t%s\t%d\t\t%d\n",i+1, item[i].name, item[i].quantity, item[i].price); total=total+(item[i].quantity*item[i].price); } printf("Total price:\t\t\t%d\n", total); total=0; } else if(b==6) { printf("Enter the number of new products:"); scanf("%d", & h); for(i=a ; i<a+h ; i++) { printf("%d.\n", i+1); printf("Enter name of the item:"); scanf("%s",& item[i].name); printf("Enter quantity:"); scanf("%d", & item[i].quantity); printf("Enter price:"); scanf("%d",& item[i].price); for(j=1; j<=i ; j++) { if(strcmp(item[i].name,item[i-j].name)==0) { printf("product already exists.\n"); printf("Enter name of the item:"); scanf("%s",& item[i].name); printf("Enter quantity:"); scanf("%d", & item[i].quantity); printf("Enter price:"); scanf("%d",& item[i].price); j=0; } } } a=a+h; } } printf("If you want to work again press 1.\nIf you want to exit press 2.\n"); scanf("%d", &f); if(f==1) { goto redo; } else if(f==2) { exit(0); } }

You might also like