- Joined
- Feb 28, 2013
- Messages
- 1,897
C++:
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//Inventory.txt
struct prodrec
{
char prodcode[5];
char prodname[10];
int prodcount;
};
main()
{
FILE *s;
s = fopen("Inventory.txt", "w");
int prodquant;
char cont, cont2, operand;
int ctr, e;
char prodcodeupd[2]; //Updating Values
char produpd[1];
int prodcountupd=0;
printf ("How many products: "); //Inventory Input
scanf ("%d", &prodquant);
struct prodrec prod[prodquant];
main:
for (ctr=0; ctr<prodquant; ctr++)
{
printf ("nProduct Code: ");
scanf ("n");
gets (prod[ctr].prodcode);
printf ("Product Name: ");
scanf ("n");
gets (prod[ctr].prodname);
printf ("Quantity: ");
scanf ("%d", &prod[ctr].prodcount);
}
printf ("nProduct CodetProduct NametQuantity");
for(ctr=0;ctr<prodquant;ctr++)
{
printf("n%stt%stt%d", prod[ctr].prodcode, prod[ctr].prodname, prod[ctr].prodcount);
}
printf("nDo you want to Update the Inventory [Y/N]:");
scanf ("n%c", &cont);
if (cont=='N'||cont=='n')
{
mainend:
printf ("nProduct CodetProduct NametQuantity");
for(ctr=0;ctr<prodquant;ctr++)
{
printf("n%stt%stt%d", prod[ctr].prodcode, prod[ctr].prodname, prod[ctr].prodcount);
fprintf(s, "%stt%stt%d", prod[ctr].prodcode, prod[ctr].prodname, prod[ctr].prodcount);
}
system ("exit");
}
else if (cont=='Y'||cont=='y')
{
update:
printf("nProduct Code: ");
scanf("n");
gets (prodcodeupd);
for(ctr=0; ctr<prodquant; ctr++)
{
if (strcmp(prodcodeupd, prod[ctr].prodcode)==0)
{
printf ("Update Code[A=Add/S=Subtract]: " );
scanf("%c", &operand);
if (operand=='A'|| operand=='a')
{
printf ("Quantity: ");
scanf("%d", &e);
prod[ctr].prodcount+=e;
}
else if (operand=='S'|| operand=='s')
{
printf ("Quantity: ");
scanf("%d", &e);
prod[ctr].prodcount-=e;
}
}
else if (strcmp(prodcodeupd, prod[ctr].prodcode)!=0)
{
printf ("Record not foundnn");
}
printf("nUpdate More [Y/N]: ");
scanf ("n%c", &cont2);
if (cont2=='Y'||cont2=='y')
{
goto update;
}
else
{
goto mainend;
}
}
}
/**/
fclose(s);
getch();
}
Now the problem is it can't find the second product code.
Any help will be appreciated :').
Attachments
Last edited by a moderator: