我对 Stack Overflow 和 C 编程相当陌生,希望我不会惹恼任何缺乏知识的人。
我正在为 Kickstarter 项目创建一个平均计算器,我想知道为什么下面的方法不起作用。不是平均水平,但是如果您要输入 1 个支持者并每天承诺 10 美元,为什么支持者和资金会翻倍,
#include <stdio.h>
#include <conio.h>
int main(void){
int loopcount = 0;
int backers = 0;
int money = 0;
int average = 0;
int tbackers = 0;
int tmoney = 0;
while(loopcount<5){
//Ask for # of backers and total money pledged.
printf("Please Enter the number of backers today, then the total money pledged today:\n");
scanf("%d\n%d", &backers, &money);
//
backers += backers;
money += money;
loopcount++;
}
//average = tmoney / tbackers;
printf("There were %d backers and the total collected was $%d.\nSo the average amount pledged was $%d", backers, money, average);
getch();
}
但以下工作正常
#include <stdio.h>
#include <conio.h>
int main(void){
int loopcount = 0;
int backers = 0;
int money = 0;
int average = 0;
int tbackers = 0;
int tmoney = 0;
while(loopcount<5){
//Ask for # of backers and total money pledged.
printf("Please Enter the number of backers today, then the total money pledged today:\n");
scanf("%d\n%d", &backers, &money);
//
tbackers += backers;
tmoney += money;
loopcount++;
}
//average = tmoney / tbackers;
printf("There were %d backers and the total collected was $%d.\nSo the average amount pledged was $%d", tbackers, tmoney, average);
getch();
}