Hello, this is my first time using this forum. I keep getting the error "term does not evaluate to a function taking 4 arguments". I do not know enough about computer sience to know what the problem could be. If i could get suggestions from someone more talented than me, on where to even look, it would be appreciated. I apologize if my code shows up messy. I am not sure how it will look when submitted. Let me know how to improve it if need be.
for (int i=199; i<linesRead; i++){ //loop to sum previous 50 closingIndex variable's, starting from day 200
for (int fifty=i; fifty>(i-50); fifty--){
fiftyDaySum = stockTable[fifty].closingIndex + fiftyDaySum;
}
for (int twoHundred=i; twoHundred>(i-200); twoHundred--){ //loop to sum previous 200 closingIndex variable's, starting from day 200
twoHundredDaySum = stockTable[twoHundred].closingIndex + twoHundredDaySum;
}
fiftyDayAverageTable[linesReadForAverages].closingIndex = fiftyDaySum/50; //assigning closingIndex to the average for the previous 50 days
fiftyDayAverageTable[linesReadForAverages].dateString = stockTable[i].dateString; //assigning dateString to the date the 50 day average started from
twoHundredDayAverageTable[linesReadForAverages].closingIndex = twoHundredDaySum/200; //assigning closingIndex to the average for the previous 200 days
twoHundredDayAverageTable[linesReadForAverages].dateString = stockTable[i].dateString; //assigning dateString to the date the 200 day average started from
fiftyDaySum = 0; //reseting sums and taking new count of lines stored
twoHundredDaySum = 0;
linesReadForAverages++;
//attempting to output data to see what the hell im doing
cout << fiftyDayAverageTable[linesReadForAverages].dateString << " " << fiftyDayAverageTable[linesReadForAverages].closingIndex << " \\ " << twoHundredDayAverageTable[linesReadForAverages].dateString << " " << twoHundredDayAverageTable[linesReadForAverages].closingIndex << endl;
}
Just an fyi you want to put your code in code tags like (insert your code) . Also if you are using headers that are unique then you will want to include those as well so people can compile and test your code for maximum help.
#include <iostream>
#include "dailyEntry.h"
#include "makeRunningAverage.h"
#include "reverseStockData.h"
usingnamespace std;
int runningAverage (int linesRead, dailyEntry stockTable[], dailyEntry fiftyDayAverageTable[], dailyEntry twoHundredDayAverageTable[])
{
double fiftyDaySum = 0;
double twoHundredDaySum = 0;
int linesReadForAverages= 0;
for (int i=199; i<linesRead; i++){ //loop to sum previous 50 closingIndex variable's, starting from day 200
for (int fifty=i; fifty>(i-50); fifty--){
fiftyDaySum = stockTable[fifty].closingIndex + fiftyDaySum;
}
for (int twoHundred=i; twoHundred>(i-200); twoHundred--){ //loop to sum previous 200 closingIndex variable's, starting from day 200
twoHundredDaySum = stockTable[twoHundred].closingIndex + twoHundredDaySum;
}
fiftyDayAverageTable[linesReadForAverages].closingIndex = fiftyDaySum/50; //assigning closingIndex to the average for the previous 50 days
fiftyDayAverageTable[linesReadForAverages].dateString = stockTable[i].dateString; //assigning dateString to the date the 50 day average started from
twoHundredDayAverageTable[linesReadForAverages].closingIndex = twoHundredDaySum/200; //assigning closingIndex to the average for the previous 200 days
twoHundredDayAverageTable[linesReadForAverages].dateString = stockTable[i].dateString; //assigning dateString to the date the 200 day average started from
fiftyDaySum = 0; //reseting sums and taking new count of lines stored
twoHundredDaySum = 0;
linesReadForAverages++;
//attempting to output data to see what the hell im doing
cout << fiftyDayAverageTable[linesReadForAverages].dateString << " " << fiftyDayAverageTable[linesReadForAverages].closingIndex << " \\ " << twoHundredDayAverageTable[linesReadForAverages].dateString << " " << twoHundredDayAverageTable[linesReadForAverages].closingIndex << endl;
}
return linesReadForAverages;
}
O, ok. How do you implement these code tags, i do not see one in this reply feature. Also, my code contains 6 header files, and 6 cpp files, one of which opens a file i have stored. Should i include them all, if need be, and how would i include the file. As i was reading about the c2064 error, it was showing ppls errors of simply 'double' assigning a variable. I thought it may have just been that in this particular function, which i cannot see. I am not good enough at programming to know what all problems this could mean.
There is a button to click on for the code tags either on the side or the bottom where it says Format: ... The button is the one that looks like <>. The other option is to simply write [co de] and then put your code in and then finish with [/co de].
Example:
[co de]
paste your code here
[/co de]
If you remove the spaces then it will work for you.
You probably do not need to put in your full code but you can if you would like. I was also thinking it is a double assignment issue but I can't debug anything I can't see. I would say include all parts of your code that call the runningaverage function. Make sure to mention what line the error message is referring to though.
I will just put all my code. That way you can see all. They should work in the order i put them in. I think. The overall goal is to find and display when the when the data 'crosses'. It is a complex enough problem, but i dont think the error should be.
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include "dailyEntry.h"
#include "getStockData.h"
//#include "analyzeStockData.h" xxxxxxxxxxxxxxxxxxx
#include "reverseStockData.h"
#include "findCrosses.h"
#include "makeRunningAverage.h"
usingnamespace std;
int main ()
{
constint MAXTABLESIZE = 3000; // Maximum size of the market data table
dailyEntry stockTable [MAXTABLESIZE]; // Array to store the daily market entry
double marketMean; // structure entries...
double standardDeviation;
dailyEntry linesStockValues [MAXTABLESIZE]; //xxxxxxxxxxxxxxxxxxxxxxxxx
int runningAverage; //xxxxxxxxxxxxxxxxxxxxxxxxx
int findCrosses;
int linesReadForAverages;
dailyEntry fiftyDayAverageTable;
dailyEntry twoHundredDayAverageTable;
dailyEntry devilsCrosses;
dailyEntry goldenCrosses;
ifstream inFile;
//string fileName = "H:\\Visual Studio 2008\\Projects\\Lab08\\MarketData.txt";
string fileName = "T:\\Visual Studio 2008\\Projects\\Lab08\\MarketData.txt"; //<-------------IMPORTANT - Drive location may need to be changed
int linesRead = 0;
try {
// Attempt to open the file for input...
inFile.open (fileName.c_str ());
// Throw an exception if it fails...
if (inFile.fail ()) {
throw (fileName);
}
}
catch (string excpt) { // Catch an exception on open failure
cout << "Failed to open input file: " << endl << excpt << endl;
return -1;
}
// Process the opened file and report the information derived
// by getStockData ( ... )
linesRead = getStockData (inFile, MAXTABLESIZE, stockTable);
if (linesRead == 0) {
cout << "No useful data extracted... No lines read." << endl;
} else {
runningAverage (linesRead,stockTable,fiftyDayAverageTable,twoHundredDayAverageTable);
//findCrosses (linesReadForAverages, fiftyDayAverageTable, stockTable, twoHundredDayAverageTable, devilsCrosses, goldenCrosses);
}
// Close the file now that we are done with it...
inFile.close ();
return 0;
}
#include <fstream>
#include <string>
#include <iostream>
#include "dailyEntry.h"
#include "getStockData.h"
usingnamespace std;
int getStockData(ifstream & inFile, int maxLines, dailyEntry stockTable [])
{
string inputLine;
string marketDateToday;
double marketValueToday; // The adjusted close of the market today
double marketOpenToday; // The opening value of the market today
int linesRead; // Count data lines processed
// Read and ignore the first line of data containing the
// headers for data columns...
getline (inFile, inputLine);
inFile.ignore ();
linesRead = 0;
// Read input data lines (up to the maximum number or until end of file is reached)
while (linesRead < maxLines) {
// Read the market date
getline (inFile, marketDateToday, ',');
// Stop reading if the end of the input file
// is encountered.
if (!inFile.good ()) {
break;
}
inFile.ignore (); // Read and ignore the separating comma
inFile >> marketOpenToday; // Read the market open value
inFile.ignore ();
inFile >> marketValueToday; // Read and ignore today's high value
inFile.ignore ();
inFile >> marketValueToday; // Read and ignore today's low value
inFile.ignore ();
inFile >> marketValueToday; // Read and ignore today's initial closing value
inFile.ignore ();
inFile >> marketValueToday; // Read and ignore today's volume reading
inFile.ignore ();
inFile >> marketValueToday; // This is today's adjusted market close value
inFile.ignore (); // Ignore the trailing newline character
// Use today's data if and only if the market open
// was not 0.0
if (marketOpenToday != 0.0) {
// Save today's date and the adjusted close value in the
// next entry in the stockTable array...
stockTable [linesRead].dateString = marketDateToday;
stockTable [linesRead].closingIndex = marketValueToday;
linesRead++;
}
}
return linesRead;
}
#include <cmath>
#include <iostream>
#include "dailyEntry.h"
#include "analyzeStockData.h"
usingnamespace std;
void analyzeStockData(int linesRead, dailyEntry stockTable [], double & marketMean, double & standardDeviation)
{ // Settin variables for function
double sumMarketValue = 0;
double sumForVariance = 0;
// Setting loop that reads and sums up the closing values in each index line in the array
for (int i=0; i<linesRead; i++){
sumMarketValue = stockTable[i].closingIndex + sumMarketValue;
}
// Calculating the mean of the closing values
marketMean = sumMarketValue/linesRead;
// Setting loop that reads and sums up the absolute value of the closing value minus the mean
// of the closing values, all to the power of 2, for each index line in the array
for (int i=0; i<linesRead; i++){
sumForVariance = pow(abs(stockTable[i].closingIndex - marketMean),2) + sumForVariance;
}
// Calculating the standard deviation of the closing values
standardDeviation = sqrt(sumForVariance/(linesRead - 1));
return;
}
#include <iostream>
#include "dailyEntry.h"
#include "makeRunningAverage.h"
#include "reverseStockData.h"
usingnamespace std;
int runningAverage (int linesRead, dailyEntry stockTable[], dailyEntry fiftyDayAverageTable[], dailyEntry twoHundredDayAverageTable[])
{
double fiftyDaySum = 0;
double twoHundredDaySum = 0;
int linesReadForAverages= 0;
for (int j=199; j<linesRead; j++){
//loop to sum previous 50 closingIndex variable's, starting from day 200
for (int fifty=j; fifty>(j-50); fifty--){
fiftyDaySum = stockTable[fifty].closingIndex + fiftyDaySum;
}
//loop to sum previous 200 closingIndex variable's, starting from day 200
for (int twoHundred=j; twoHundred>(j-200); twoHundred--){
twoHundredDaySum = stockTable[twoHundred].closingIndex + twoHundredDaySum;
}
fiftyDayAverageTable[linesReadForAverages].closingIndex = fiftyDaySum/50; //assigning closingIndex to the average for the previous 50 days
fiftyDayAverageTable[linesReadForAverages].dateString = stockTable[j].dateString; //assigning dateString to the date the 50 day average started from
twoHundredDayAverageTable[linesReadForAverages].closingIndex = twoHundredDaySum/200; //assigning closingIndex to the average for the previous 200 days
twoHundredDayAverageTable[linesReadForAverages].dateString = stockTable[j].dateString; //assigning dateString to the date the 200 day average started from
//reseting sums and taking new count of lines stored
fiftyDaySum = 0;
twoHundredDaySum = 0;
linesReadForAverages++;
//attempting to output data to see what the hell im doing
cout << fiftyDayAverageTable[linesReadForAverages].dateString << " " << fiftyDayAverageTable[linesReadForAverages].closingIndex << " \\ " << twoHundredDayAverageTable[linesReadForAverages].dateString << " " << twoHundredDayAverageTable[linesReadForAverages].closingIndex << endl;
}
return linesReadForAverages;
I've only had a quick look but it looks like one issue is that in main you are declaring local variable int runningAverage and then later calling the function runningAverage (linesRead,stockTable,fiftyDayAverageTable,twoHundredDayAverageTable);. That is where the initial error is likely coming from.
From what I can see, and I have only quickly glanced at the code so bear with me if this turns out incorrect, you don't need to be locally declaring runningAverage at all and in general you shouldn't be naming a function and variable the same thing anyways. That can easily lead to user confusion not to mention compiler errors. I would delete the variable declaration and try to run the code if I were you.
Wow, that is amazing. That would have taken me days to figure out. I cant believe you found it that fast. It fixed that error, now i just get one that says ... cannot convert parameter 3 from 'dailyEntry' to 'dailyEntry []', in the main function where i am calling runningaverage. Line 90.