gpt4 book ai didi

c - while 循环中的 printf 打印两次而不是一次

转载 作者:太空宇宙 更新时间:2023-11-04 04:14:39 25 4
gpt4 key购买 nike

<分区>

在这段代码中,它需要计算运算符出现的次数。它不计算它,在运行代码时它打印“请输入注释。完成按 Q:”两次,我不知道出了什么问题。

#include <stdio.h>

int main(void)
{

char note;
int result1 = 0, result2 = 0, result3 = 0, result4 = 0;


do
{
printf("Please enter a note. to finish press Q:\n");
scanf("%c", &note);
switch (note)
{
case'+':
result1 = result1 + 1;
break;
case'-':
result2 = result2 + 1;
break;
case'*':
result3 = result3 + 1;
break;
case'/':
result4 = result4 + 1;
break;
}

} while (note != 'Q');

printf("+ appears %d times\n", result1);
printf("- appears %d times\n", result2);
printf("* appears %d times\n", result3);
printf("/ appears %d times\n", result4);

system("pause");
}

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