小编Oda*_*dar的帖子

C 循环直到给出 0

我正在尝试创建一个循环,让用户逐个输入数字并计算所有这些数字的总和,直到用户输入 0 作为输入。但是,我的代码只运行一次,然后就停止了。

#include <stdio.h>

int main(void) {
    int i = 0;
    int num;
    int total = 0;

    printf("Give me a number \n");
    scanf("%d", num);
    
    if(num < 0 && num > 0){
        printf("Give me a number \n");
        scanf("%d", num);
        total = total + num;
        i = i + 1;
    }

    printf("The total is %d", total);
}
Run Code Online (Sandbox Code Playgroud)

c loops for-loop while-loop

-1
推荐指数
1
解决办法
3637
查看次数

标签 统计

c ×1

for-loop ×1

loops ×1

while-loop ×1