循环问题 谢谢
#include<stdio.h>#include<string.h>
#define n 4
struct drug
{
char name[20];
float price;
int quantity;
};
struct update
{
char na[20];
float p_increase;
int q_increase;
};
void main()
{
int i,j;
float sum;
struct drug items[4]={{"a",39,40},{"b",38,99},{"c",12,400},{"d",31,120}};
struct update up;
char ch;
do
{
printf("please input the item you want update\n");
scanf("%s %f %d",up.na,&up.p_increase,&up.q_increase);
for(i=0;i<n;i++)
{
if(strcmp(up.na,items[i].name)==0)
{
printf("the %s is to be updated\n",up.na);
if(up.q_increase+items[i].quantity<0)
printf("sorry!\n");
else
items[i].quantity=items[i].quantity+up.q_increase;
items[i].price=items[i].price+up.p_increase;
sum=items[i].price*items[i].quantity;
printf("%s %f %d %f\n",items[i].name,items[i].price,items[i].quantity,sum);
}
else if(strcmp(up.na,items[1].name)&&strcmp(up.na,items[2].name)&&strcmp(up.na,items[3].name)&&strcmp(up.na,items[0].name))
printf("no the item,sorry!\n");
}
printf("any one else?y or no\n");
scanf("%c",&ch);
}while(ch=='y'||ch=='Y');
}
这个程序怎么不能循环啊
我准备输入Y 再循环一次 但是直接显示press any key to continue 为什么啊??谢谢
还有我这程序红色部分 我想优化下 怎么办?