arrays - 当我在字符(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 你想继续吗?是或否:是
选择了错误的选择。请选择正确的一项 [程序完成]
解决方案
推荐阅读
- avro - Avro:可以避免生产者和消费者之间共享 Schema 吗?
- java - java.lang.ClassNotFoundException: com.google.cloud.sql.mysql.SocketFactory
- javascript - VS2019 ASP.NET项目中Typescript导入axios
- maxmind - Maxmind Insights API 中 user_type 值的含义
- angular - 从 v7 到 v8 的 Angular 通用更新
- javascript - brower.acceptAlert 不是 webdriverIO 中的函数
- ruby-on-rails - Rails 6 Active Storage:找不到或构建 blob:预期可附加...((重新)设置附件时的问题)
- java - JSP 页面如何找到正确的参数设置器
- c# - 如何在 Treeview 中更改 Focused TreeNode 背景颜色
- python - Seaborn 热图中的按行颜色比例