C ++程序给出了过多的参数警告

编程入门 行业动态 更新时间:2024-10-26 02:31:01
本文介绍了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 ++程序给出了过多的参数警告

本文发布于:2023-11-25 12:16:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629711.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:出了   参数   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!