while..do循环在C中
我最近刚学过C编程。事实上,我是编程的初学者。目前,我正在读一本名为《C编程,绝对初学者指南》的书。 我不太明白,他们使用do…while循环:while..do循环在C中,c,C,我最近刚学过C编程。事实上,我是编程的初学者。目前,我正在读一本名为《C编程,绝对初学者指南》的书。 我不太明白,他们使用do…while循环: if (choice == 'n') { choice = 'N'; } } while (choice != 'N'); 这用于用户类型“n”而不是“n”的情况。但我重新键入如下内容: while ((choice != 'N')||(choice!='n')); while循环仍在继续 抱歉,伙计们,时间不够(我
if (choice == 'n')
{
choice = 'N';
}
} while (choice != 'N');
这用于用户类型“n”而不是“n”的情况。但我重新键入如下内容:
while ((choice != 'N')||(choice!='n'));
while循环仍在继续
抱歉,伙计们,时间不够(我差点错过校车)
以下是本书的完整原始代码:
float num1, num2, result;
char choice;
do {
printf("Enter your first number to multiply: ");
scanf(" %f", &num1);
printf("Enter your second number to multiply: ");
scanf(" %f", &num2);
result = num1 * num2;
printf("%.2f times %.2f equals %.2f\n\n",
num1, num2, result);
printf("Do you want to enter another pair of numbers ");
printf("to multiply (Y/N): ");
scanf(" %c", &choice);
// If the user enters a lowercase n, this if statement will
// convert it to an N
if (choice == 'n')
{
choice = 'N';
}
} while (choice != 'N');
return 0;
你的布尔逻辑不正确,你要找的是
while ((choice != 'N')&&(choice!='n'));
在使用的情况下,或者如果其中任何一种情况是真的,它将继续,并且始终如此
|选择|选择!='选择或|和||X |真|真|真|真|
|n |真|假|真|假|
|N | false | true | true | false |你的情况总是真实的你发布的任何一个片段中都没有
do
。你到底在问什么?无法理解你的意图。