gpt4 book ai didi

c - 为什么 if block 之后的 scanf 不起作用,它只显示 "press 1 to enter again:"并且不再接受输入

转载 作者:行者123 更新时间:2023-11-30 20:35:08 25 4
gpt4 key购买 nike

scanf if block 不起作用后的语句有人可以帮助我

#include<stdio.h>
main()
{

int input,itemno,input2;
int name1,price1,name2,price2,name3,price3;
printf("enter input:\n");
scanf("%d", &input);
if(input==1)
{
printf("enter number of items:\n");
scanf("%d",&itemno);
if(itemno<=3)
{
printf("enter name and age:\n");
scanf("%d %d\n %d %d\n %d %d\n",&name1,&price1,&name2,&price2,&name3,&price3);
}
else
printf("you can only enter 3 students");
}
printf("press 1 to enter again: \n");
scanf("%d",&input2);
if(input2==1)
{
printf("hey");
}
}

最佳答案

scanf("%d %d\n %d %d\n %d %d\n",&name1,&price1,&name2,&price2,&name3,&price3);

不要在 scanf 函数调用中使用转义字符。

关于c - 为什么 if block 之后的 scanf 不起作用,它只显示 "press 1 to enter again:"并且不再接受输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40373806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com