注册 登录
编程论坛 C++教室

<求助>编程问题

shodawn 发布于 2016-03-01 19:51, 4288 次点击
求多个整数和,输入非数字才开始求和,帮我看看
#include<stdio.h>
int main()
{
    int sum=0,value=0;
    while(scanf("%d",&value))
    {
        sum+=value;
    }
    printf("%d",sum);
    return 0;
}
3 回复
#2
yangfrancis2016-03-01 20:23
运行无误
#3
rjsp2016-03-02 08:24
    while(scanf("%d",&value))
    {
        sum+=value;
    }
你是如何结束这个循环的?

“输入非数字才开始求和” --- 这是你的要求呢,还是你想解决掉的bug?
#4
农民工2016-03-03 15:53
有什么问题吗?
Return Value

Both scanf and wscanf return the number of fields successfully converted and assigned; the return value does not include fields that were read but not assigned. A return value of 0 indicates that no fields were assigned. The return value is EOF for an error or if the end-of-file character or the end-of-string character is encountered in the first attempt to read a character.

1