【发布时间】:2014-02-23 14:30:41
【问题描述】:
我有以下代码,如果按下除1 & 2 之外的任何键,我想终止while 循环。但只有do 执行一次。而不是while。为什么我的while condition 总是假的。请指导:
char a;
do
{
printf("To Enter the Employee sales press 1 \n");
printf("To Add more items press 2 \n ");
printf("Press any key to Terminate \n\n");
scanf("%c", &a);
if ( a == '1' )
{
printf("1 is presed ");
}
else if(a == '2')
{
int c;
printf("entre Value:");
scanf("%d",&c);
printf("\n");
addItem( &myArray, &size, c );
printitems(myArray, size);
}
}while(a == '1' || a == '2');
编辑 很抱歉,它是在单个 qout 中。我忘了放最新的代码。即使使用 qoutes,它也不会运行 while。
【问题讨论】:
-
a == '1'...(单引号)?
标签: c loops if-statement logic