首页 > 解决方案 > 当我在字符(y 或 n)的位置取字符串(是或否)时,程序无法继续

问题描述

程序成功执行,但没有继续。请帮忙。当我将 y 或 n 作为字符时,它会起作用。

#include <stdio.h>
#include <conio.h>
int main()
{
    int a[20], n, i, sum = 0;
    char c[10];
    clrscr();
    do
    {
        printf("How many numbers you want to sum: ");
        scanf("%d", &n);
        for (i = 0; i < n; i++)
        {
            printf("\nwrite the number: ");
            scanf("%d", &a[i]);
            sum = sum + a[i];
        }
        printf("\nSum of numbers are %d", sum);

        printf("\nDo you want to continue. yes or no:  ");
        scanf("%s", c);
    } while (c == "yes");
    if (c == "no")
        printf("\nThanking You");
    else
        printf("\nWrong choice selected. Please select correct one");

    return 0;
    getch();
}

错误如下所示。你想和多少个数字:3

写数字:1

写数字:2

写数字:3

数字总和是 6 你想继续吗?是或否:是

选择了错误的选择。请选择正确的一项 [程序完成]

标签: arrayscstringrepeat

解决方案


推荐阅读