C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 18th, 2015, 11:17 AM
courtney21 courtney21 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2015
Posts: 1 courtney21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 5 sec
Reputation Power: 0
Memory & arrays - Reading in data and finding the sum of that data

I have a final integrated project that encompasses what we've learned in C++ and MATLAB. This involves taking a .txt file, reading that data into C++ and doing some calculations.
The .txt file I have right now has 4 columns of data. I used the getline command to get the column headers of the .txt file out of the way so that I can work only with the numbers I have.
I need to take the sum of all 96 values that are in the second column of my .txt file, which is supposed to be sunlight measured in W/m^2. I'm having trouble summing this data and would like to know if anyone has any suggestions on how I can go about this. Thanks for your time! Feel free to ask any questions.


Below is my current code:

#include <iostream>
#include <iomanip> //for setprecision (if you choose to use it)
#include <fstream> //for reading in data
using namespace std;
int main()
{
char column_headers[100]; //creates a character array to hold 1st text line
double date_time, sunlight, power_output, temp;
double values[96]={sunlight};
ifstream readin;
readin.open("Solar_Panel1.txt");
if (!readin) //if file doesn't open correctly
{
cout<<"Unable to open requested file. Try again."<<endl;
system("pause");
exit (0);
}
else
{
readin.getline(column_headers,100); //read & store characters up to 100 maximum length
cout<<column_headers<<endl; //let's see what we captured w/ getline
cout<<values[96]<<endl;
while(readin>>date_time>>sunlight>>power_output>>temp)
{
double sum=0;
for (int i=0; i<96; i++)
{
sum=sum+values[i];
}
cout<<"sum = "<<sum<<endl;
cout<<values[96]<<endl;
}
}
readin.close();
system("pause");
return 0;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Memory & arrays - Reading in data and finding the sum of that data


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap