473,791 Members | 2,853 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to calculate the values in a table

5 New Member
Im trying to work out the total values of a table, which i have read from a file

x y
1.0 2.876
2.6 4.234
3.7 8.874
4.5 7.698
6.0 9.932

I want to work out the total values of x, i.e sum of.

How would i implement this, please. thanks, here is what i have so far. Im new so there maybe quite a few errors. Its displaying the file ok, and the number of values, but i cant get it to work out the sum of the x values, please, help.
thanks.


#include <stdio.h>
#include <math.h>

int main(void)

{
char line [101];
char *line_ptr;
double x, y;
int no_values=-1;
double sum_x;
int i=0;

FILE *input_stream;

if ((input_stream= fopen("test_dat a.dat", "r")) != NULL)

{
while ((line_ptr=fget s(line, sizeof(line), input_stream))! = NULL)

{
if ((sscanf (line, "%d %d", &x, &y)) != 2)
{
no_values++;
fprintf (stdout, "%s\n", line);
}
}
}

fprintf(stdout, "\n\n\n\nno_val ues: %d\n", no_values);

for (i=0; i<=no_values; i++)

{
sum_x= x;
}

fprintf(stdout, "\n\n\n\nsu m_x: %lf\n", sum_x);


}
Dec 13 '06 #1
1 1468
Ganon11
3,652 Recognized Expert Specialist
http://www.thescripts. com/forum/thread576241.ht ml
Dec 13 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

25
5199
by: kie | last post by:
hello, i have a table that creates and deletes rows dynamically using createElement, appendChild, removeChild. when i have added the required amount of rows and input my data, i would like to calculate the totals in each row. when i try however, i receive the error: "Error: 'elements' is null or not an object"
3
4878
by: muzamil | last post by:
To get rid of redundant data in a table, my cleint will be providing something like this: IDtokeep Ids to delete 34 24,35,49 12 14,178,1457 54 32,65,68 I have to write a script for each of the above rows which looks like
1
1543
by: ferky | last post by:
I have this code below when I asign strOldTkinit = strNewTkinit and then read the new value for the strNewTkinit from the recordset the strOldTkinit changes the value also. So when I run my comparison the values is always equal even though I read a new value from the recordset. Please help. function getRSXML(strSQL) { var adoCnn = null; var adoRst = null;
1
2232
by: tomektomeknyc | last post by:
I did an interactive program to input and store employee paycheck information including total net pay into txt file. I can read it from txt file but how can i lets say modify it to calculate the average of all totals,based on many user inputs to txt file?
0
1344
by: demon | last post by:
if i give you a htmltable object , how can i calculate the table's height in browser?
4
3180
by: Simon Gare | last post by:
Hi all, need to do a simple form calculation in asp based on values in 2 other field and enter that data into table. (field)SubTotal + (field)VAT = (Result in field)GrandTotal Any resources available Thanks
1
1446
by: jchimanzi | last post by:
How can i rewrite the following code correcting all problems found void calculatevalues (const int &a, float *b, int &c) { d = 20.4; if (*a =0) *a += 1
1
1538
by: manojsingh | last post by:
hi, I am generating combo.All combo has diffrent names. combo contain three values - L,EL and LWP Agian there is three text box that shows the rest CL,EL,LWP values which is not editable. And on submit button's click i want to check the number of select CL in combo should not exceeds the given CL value in CL textbox, and i need to do same for EL and LWP. Please help
1
2851
by: shalit.dror | last post by:
I have an XML files that contains grades in different subjects from year 2005  2007 . In the HTML file I have several drop down list that contain all the names of the subjects. If I select for example history from the first one , I get the grade for 2005 in the first field, then the grade for 2006 in the field next to it and the grade for 2007 in the third field. Then I go to the second drop down list , select another subject name and...
1
1723
by: ekariuki | last post by:
Hallo, I have a table Routes that contains a route name and when the route runs. I would like to calculate the difference between the last run Day and the one after it. This will populate in the RunDateDiff field. My table: Tbl_Route RouteName RunDate Stop RunDateDiff A 12/1/2009 Clinton A 12/3/2009 Townsent A 12/3/2009 Nowhere
0
9669
marktang
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...
0
9515
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,...
0
10426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
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...
1
10154
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,...
0
9993
tracyyun
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...
1
7537
isladogs
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...
1
4109
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2913
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.