【发布时间】:2018-11-22 12:55:12
【问题描述】:
我有一个 C 语言作业,要求用户向数组输入值。我的想法是创建两个不同的数组,一个包含整数值,另一个包含字符值。到目前为止,这是我的代码:
#include <stdio.h>
int main()
{
char continued;
int i = 0;
char instrType[10];
int time[10];
printf("\nL-lock a resource");
printf("\nU-unlock a resource");
printf("\nC-compute");
printf("\nPlease Enter The Instruction Type");
printf(" and Time Input:");
scanf("%c", &instrType[0]);
scanf("%d", &time[0]);
printf("\nContinue? (Y/N) ");
scanf("%s", &continued);
i = i + 1;
while (continued == 'Y' || continued == 'y')
{
printf("\nL-lock a resource");
printf("\nU-unlock a resource");
printf("\nC-compute");
printf("\nPlease Enter The Instruction Type ");
printf("Time Input:");
scanf("%c", &instrType[i]);
scanf("%d", &time[i]);
printf("\nContinue? (Y/N) ");
scanf("%s", &continued);
i = i + 1;
}
return 0;
}
当我尝试输入新值时,循环刚刚停止,即使我输入“Y”表示“是继续”,条件也没有检查该值,请帮助:(
【问题讨论】: