level 1
一个关于设置和查询商品价格的题目,部分代码如下
while(1)
{
if(scanf("Set item %d price to %f",&index,&price) == 2)
{
item[index - 1] = price;
}
if(scanf("Print item %d Price",&index) == 1)
{
printf("%f\n",item[index - 1]);
}
}
预期效果是等待输入,输入
正确的
命令后执行设置或查询价格,但实际运行过程中只有第一次输入时正常执行命令,然后就进入死循环不让输入了,请问是哪里有错误
2023年01月11日 05点01分
1
while(1)
{
if(scanf("Set item %d price to %f",&index,&price) == 2)
{
item[index - 1] = price;
}
if(scanf("Print item %d Price",&index) == 1)
{
printf("%f\n",item[index - 1]);
}
}
预期效果是等待输入,输入
正确的
命令后执行设置或查询价格,但实际运行过程中只有第一次输入时正常执行命令,然后就进入死循环不让输入了,请问是哪里有错误
