-1
プログラムは、商品の総コストを計算し、商品、製品、および価格を請求書としてユーザに表示する必要があります。私は基本的な機能が使用されるように私はCでのプログラミングの初心者であることを覚えておいてください。その答えとしてこれを行うプログラムの実行は、それが動作を停止すると言います
#include<stdio.h>
#include<string.h>
typedef struct
{
float price;
int quantity;
char product;
}Billing;
typedef struct
{
int code;
char product;
float price;
}Stocks;
main()
{
Stocks A;
Billing B;
FILE*s;
FILE*c;
printf(" Welcome to I.A.M Cash & Carry\n#8 New Trincity Industrial Estate\nTrincity\n");
printf("=================================\n");
void transfer(Billing,Stocks,FILE*,FILE*);
transfer(B,A,s,c);
}
void transfer(Billing B,Stocks A,FILE*s,FILE*c)
{
int count;
s=fopen("C:\\stock.txt","r");
int counter=0;
while(fgetc(s)!=EOF)
{
counter++;
}
fclose(s);
count=counter;
Stocks D[count];
int x;
s=fopen("C:\\stock.txt","r");
for(x=0;x<count;x++)
{
fscanf(s,"%d",&D[x].code);
fscanf(s,"%s",D[x].product);
fscanf(s,"%f",&D[x].price);
}
fclose(s);
void menu(Billing,Stocks[],FILE*,FILE*,int);
menu(B,D,s,c,count);
}
void menu(Billing B,Stocks D[],FILE*s,FILE*c,int count)
{
printf("1)Enter items for billing\n");
printf("2)Quit\n");
void choice(Billing,Stocks[],FILE*,FILE*,int);
choice(B,D,s,c,count);
}
void choice(Billing B,Stocks D[],FILE*s,FILE*c,int count)
{
int x;
printf("Enter choice:\n");
scanf("%d",&x);
if((x<1) || (x>2))
{
printf("Choice invalid\nPlease Re-enter\n");
menu(B,D,s,c,count);
}
if(x==1)
{
void submenu(Billing,Stocks[],FILE*,FILE*,int);
submenu(B,D,s,c,count);
}
if(x==2)
{
printf("Thank you, Have a great day\n");
}
}
void submenu(Billing B,Stocks D[],FILE*s,FILE*c,int count)
{
int x,z,quan,prod;
float sum=0;
float prices=D[x].price*quan;
c=fopen("C:\\bill.txt","w");
do{
printf("Select choice:\n");
printf("1)Enter items\n");
printf("2)Quit");
scanf("%d",&x);
if(x==1)
{
printf("Enter product code:");
scanf("%d",&prod);
for(z=0;z<count;z++)
{
if(prod==D[x].code)
{
printf("Enter quantity:");
scanf("%d",&quan);
fprintf(c,"%d ",quan);
fprintf(c,"%s ",prod);
fprintf(c,"%5.2f\n",D[x].price*quan);
sum= sum + prices;
}
}
}
if(x==2)
{
printf("Thank you, Have a great day\n");
}
}while(x!=2);
fclose(c);
void countbill(Billing,FILE*,float);
countbill(B,c,sum);
}
void countbill(Billing B,FILE*c,float sum)
{
int y;
c=fopen("C:\\bill.txt","r");
int x=0;
while(fgetc(c)!=EOF)
{
x++;
}
fclose(c);
y=x;
Billing V[y];
void displaybill(Billing[],FILE*,float,int);
displaybill(V,c,sum,y);
}
void displaybill(Billing V[],FILE*c,float sum,int y)
{
int x;
c=fopen("C:\\bill.txt","r");
for(x=0;x<y;x++)
{
fscanf(c,"%d",&V[x].quantity);
fscanf(c,"%s",V[x].product);
fscanf(c,"%f",&V[x].price);
printf("%d %s %f\n",V[x].quantity,V[x].product,V[x].price);
}
printf("Total=%f",sum);
}
デバッガ出力
デバッグしましたか?あなたはどんなエラーを出していますか? – Carcigenicate
デバッガの使用方法を学びます。それは将来報いを受けるでしょう。 –
@Carcigenicateデバッグをクリックすると、コンパイラがクラッシュします。 – iGunta