I'm reading data from a file into an array of floats to eventually use in the prices::assign function. However, the array never gets populated and that makes it hard to sleep at night. My doctor says I should go to you guys for my health. I've found on other forums that something like this method (not this one, obviously) should work. What am I doing wrong? Help me cplusplus.com, your my only hope!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
//
// main.cpp
// Make Up Assignment
//
//
#include <iostream>
#include <fstream>
using namespace std;
struct Date
{
int month,day,year;
};
class prices
{
private:
Date date[100];
float open[100],high[100],low[100],close[100],adjustedClose[100];
public:
int assign(int countera,
int daya,
int montha,
int yeara,
float opena,
float higha,
float lowa,
float closea,
float adjustedClosea);
float getOpen(int i);
float getHigh(int i);
float getLow(int i);
float getClose(int i);
float getAdjustedClose(int i);
};
int prices::assign(int countera, int daya, int montha, int yeara, float opena, float higha, float lowa, float closea, float adjustedClosea)
{
open[countera]=opena;
high[countera]=higha;
low[countera]=lowa;
close[countera]=closea;
adjustedClose[countera]=adjustedClosea;
countera++;
return countera;
};
class div
{
private:
Date date[100];
float dividends[100];
public:
};
string PIIIXdivPath ="/Users/main/Documents/C++ 2014/Make Up Assignment/Make Up Assignment/PIIIX dividend.csv";
string PIIIXpath="/Users/main/Documents/C++ 2014/Make Up Assignment/Make Up Assignment/PIIIX.csv";
string PTTAXdivPath="/Users/main/Documents/C++ 2014/Make Up Assignment/Make Up Assignment/PTTAX dividend.csv";
string PTTAXpath="/Users/main/Documents/C++ 2014/Make Up Assignment/Make Up Assignment/PTTAX.csv";
int main(int argc, const char * argv[])
{
prices markhor;
int dateTemp[3];//stores date digits for prices::assign
int count=0;//stores
float data[6];//stores open, high, low, close, and adjusted close
ifstream PIIIX;
ifstream PIIIXdiv;
ifstream PTTAX;
ifstream PTTAXdiv;
string buffer;//
PIIIX.open(PIIIXpath);
if (!PIIIX) {
cout<<"\nPIIIX cannot open, file has ebola\n";
}
PIIIX>>buffer;
cout<<buffer;
PIIIX>>buffer;
cout<<buffer<<endl;
for (int x=0; x<10; x++) {
PIIIX>>dateTemp[0]>>dateTemp[1]>>dateTemp[2];//get date
PIIIX>>data[0]>>data[1]>>data[2]>>data[3]>>data[4]>>data[5];
cout<<dateTemp[0]<<dateTemp[1]<<dateTemp[2]<<data[0]<<data[0]<<data[1]<<data[2]<<data[3]<<data[4]<<data[5]<<endl;
}
return 0;
}
|
This is the first couple of lines in the file I'm trying to read
Date,Open,High,Low,Close,Volume,Adj Close
2014-12-05,191.00,191.00,191.00,191.00,000,191.00
2014-12-04,190.69,190.69,190.69,190.69,000,190.69
2014-12-03,190.90,190.90,190.90,190.90,000,190.90
2014-12-02,190.14,190.14,190.14,190.14,000,190.14
2014-12-01,188.92,188.92,188.92,188.92,000,188.92
2014-11-28,190.21,190.21,190.21,190.21,000,190.21
2014-11-26,190.69,190.69,190.69,190.69,000,190.69
2014-11-25,190.11,190.11,190.11,190.11,000,190.11