本文介绍了C ++程序给出了过多的参数警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我几乎不知道自己在做什么,我有这段代码试图解决一些简单的数学问题:
I barely know what I'm doing, I have this code where I try to solve some simple math:
#include<stdio.h> #include<conio.h> #include<stdlib.h> main() { int n, sum=0; printf("ENTER NUMBER:"); scanf("%i",n); while(n>0) { sum+=n; n--; } printf("\n sum is:",sum); return 0; }问题是当我尝试对其进行编译时,出现此错误:
The problem with it is that when I try to compile it I get this error:
main.cpp:23:26: warning: too many arguments for format [-Wformat-extra-args] printf("\n sum is:", sum); 推荐答案编译器警告您忘记指定格式字符串中sum的字段.您可能想要:
The compiler is warning you that you forgot to specify the field for sum in the format string. You probably wanted:
printf("\n sum is: %d",sum);如上所述,它将不打印总和,并且将不使用总和值.因此,警告.
As above, it will not print the sum, and the sum value will not be used. Hence the warning.
更多推荐
C ++程序给出了过多的参数警告
发布评论