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: -
-
totalWeight=weightOfPounds;
-
outFile2<< "Total weight" << totalWeight << endl;
-
-
11 3335 donbock 2,426
Recognized Expert Top Contributor
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,
Is it not possible to keep a running total of the 'pounds' with an expression like
sum+=pounds;
.......in a for loop?
donbock 2,426
Recognized Expert Top Contributor
the input values are read in from an input file,
OK. What is the format of the input file ... is it simply a newline-separated list of floating-point values, is it a list of " label=value" assignments, is it something else.
And most importantly, let me repeat my earlier question. How do you know which input values do NOT go into the sum?
if have of numbers written separetly in a for loop and those numbers to totaled into one sum. how would u do that;
example:
Total weight21.5
Total weight30
Total weight50.8
Total weight12.4
Total weight42.6
Total weight31.5
Total weight22.4
Total weight71.3
the total sum=211.2
these are reading in from a input file.
Anything will help please. boxfish 469
Recognized Expert Contributor
Make a variable for the total sum, set it to zero, and then every time you read in a number from the file, add it to the total.
Hope this helps.
donbock 2,426
Recognized Expert Top Contributor
In your other thread you said that some of the input values shouldn't go into the sum. Is that still the case or did I misunderstand?
Name of the other thread: "PLEASE Im having so much trouble with this calculation."
What step of the problem are you having trouble with?
... Can you read the input file?
... Can you extract the input values from the input file?
... Can you add the input values together into a sum?
Are you stuck and don't know how to start?
Did you write a program but it either won't compile or it doesn't do what you want?
donbock 2,426
Recognized Expert Top Contributor
Suppose all of the input values were in a global array like this:
double inputValues[10];
How would you compute the sum of all entries in the array?
In your other thread you said that some of the input values shouldn't go into the sum. Is that still the case or did I misunderstand?
Name of the other thread: "PLEASE Im having so much trouble with this calculation."
What step of the problem are you having trouble with?
... Can you read the input file?
... Can you extract the input values from the input file?
... Can you add the input values together into a sum?
Are you stuck and don't know how to start?
Did you write a program but it either won't compile or it doesn't do what you want?
the program is reading from the input file,
I started the program i added the program to the thread so you can see what im stuck on.
My program is readng each weight separtley but i want it to read in the sum of all the weights.I am trying to add the each indvidul weight I called this variable "weightOfBagsFo rPassenger" to come up with a total of 211.2. I cant include the last weight of 71.3 because that weight has been rejected.
I declared a new variable called totalSum=0;
from my program i cant determine how to add the total of the "weightOfBagsFo rPassenger"
into one sum.
does that make sense?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: DJTB |
last post by:
zodb-dev@zope.org]
Hi,
I'm having problems storing large amounts of objects in a ZODB.
After committing changes to the database, elements are not cleared from
memory. Since the number of objects I'd like to store in the ZODB is too
large to fit in RAM, my program gets killed with signal 11 or signal 9...
Below a minimal working (or actually: it doesn't work because of memory
|
by: dbuser |
last post by:
Hi,
I need help on a problem, as described below. I am reading a file
"input.txt"which has data like this:
abc def gh izk lmnopq rst uvwxyz
I am using fstream object to read the file and writing into a dynamic
array. My problem is that the array shows extra z and probably because
of this further processing gives run time error in borland compiler.
Can you please tell me, if the problem is related to handling end-of
line , how do i do...
|
by: Henk |
last post by:
Hi Guys,
(see actual code below)
I wrote a little program that is supposed to read a file (input.txt)
into memory (using a stack) and then reverse the file and display it to
output. It works, but I still get some errors when i try to compile
it:
stack.c: In function 'reverseFile'
|
by: harold |
last post by:
Dear all,
Maybe I stared on the monitor for too long, because I cannot find the
bug ...
My script "transition_filter.py" starts with the following lines:
import sys
for line in sys.stdin :
try :
|
by: Mike |
last post by:
Hi,
I am new to C and having problems with the following program.
Basically I am trying to read some files, loading data structures into
memory for latter searching.
I am trying to use structres and arrays of pointers to them.
I have gotten the program to compile with gcc on WinXP.
If the file i read doesnt have alot of records, it runs thru. But once
i add more, it dies. In this program i have 4 files setup to read. The
| |
by: katz911 |
last post by:
Hello,
I've encountered a strange problem which I can't seem to explain.
I've written a simple C++ class that deals with a certian binary file.
In one of the methods there, I wish to update a file - namely to read
a certain field whose offset I know, and then write to another field,
whose offset I also know.
In order to read the data, I first use file.seekg(offset, ios::beg),
and then a read command; I've checked the variable, and...
|
by: jacob navia |
last post by:
I am trying to compile as much code in 64 bit mode as
possible to test the 64 bit version of lcc-win.
The problem appears now that size_t is now 64 bits.
Fine. It has to be since there are objects that are more than 4GB
long.
The problem is, when you have in thousands of places
|
by: psy_berpunk |
last post by:
hey, i'm trying to write a simple program to read gif87a non-
interlaced format with a single image-descriptor ---
I am using djgpp on windows xp.
Sounds simple enough, unfortunatly data in the format is arranged
primarily in single-byte unsigned integers.
So i've been reading them in a chars and casting them as unsigned
chars into an int.
|
by: steve005 |
last post by:
Hi, I am writing a binary file with matlab that consists of a couple
hundred double values and then reading it in with c++. The problem
arises in c++ when I try and read in the files. At a specific point it
stops and wont read any more values. I use this code to open it and
read it:
if( (err = fopen_s( &fp,"C:/simfile1.tmg0" , "rb" )) != 0 );
fread(&coneAngle,sizeof(double),1,fp);
After about twenty simmilar reads it fails, returns an...
|
by: Arto Viitanen |
last post by:
I am using WriteXML/ReadXml pair to save DataSet for later use. DataSet
is built by reading textfiles and storing their data to different
DataTables. Each file contains several complex values, that are
represented using a DataValue object. DataValue is an abstract class,
that has subclasses that implement the value (for example; ValBlkValue
represents a vector of floating values).
Class DataValue implements IXmlSerializable interface and...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |