从文件中读取值并计算总和时出现问题 [英] Problems reading values from a file and calculating the sum

查看:63
本文介绍了从文件中读取值并计算总和时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须计算我的计划的总磅数。我得到每磅计算,但我必须将所有这些磅加起来。

问题是总磅数之一不应该计算。


我该怎么做我正在努力


输出:

总重量21.5

总重量30

总重量508.8

总重124.4

总重42.6

总重31.5

总重22.4

总重71.3这总不计入总磅数


总重量必须出来到211.2磅

我无法计算如何获得这个数额。任何想法都会有所帮助!



这里是计算上述代码的代码:

i have to calculate a total amount of pounds for my program. i am getting each pound calculated but i have to add up all those pounds into one total.
the problem is one of the total pounds is not supposed to be calculated.

how do i do this I am struggling

OUTPUT:
Total weight21.5
Total weight30
Total weight50.8
Total weight12.4
Total weight42.6
Total weight31.5
Total weight22.4
Total weight71.3 this total cant be included in the total pounds

the total amount of weight has to come out to 211.2pounds
I cant figure how to get that amount. Any ideas will help!


here is the code that calculates the above:

展开 | 选择 | 换行 | 行号

推荐答案

所以...你有一个输入值列表,你想要计算所有这些输入值的总和,除了应该省略的总和之外。


输入值与众不同之处有什么区别?你怎么认识哪一个不被其他人加入?通过你,我的意思是你作为一个人 - 我们会担心你的计算机程序如何识别它。


这些输入值是否来自键入的用户输入,从输入文件中读取,作为输入参数传递给你的函数,还是硬编码到你的程序中?
So ... you have a list of input values and you want to compute the sum of all these input values except for one that should be left out of the sum.

What is distinctive about the input value that doesn''t go into the sum? How do you recognize which one doesn''t get added in with the others? By "you", I mean you as a person -- we''ll worry about how your computer program recognizes it later.

Do these input values come from typed user input, read from an input file, passed as input arguments to your function, or are they hard-coded into your program?


从输入文件读入输入值,
the input values are read in from an input file,


是不是可以使用像

sum + =磅;

...这样的表达来保持''磅'的运行总计..​​. ....在for循环中?
Is it not possible to keep a running total of the ''pounds'' with an expression like
sum+=pounds;
.......in a for loop?


这篇关于从文件中读取值并计算总和时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆