quick
December 11th, 2003, 11:54 AM
ok i have two problems.
the first one i am trying to calculate how many times something happens and increment an element in array each time that happens. this is for multiple objects that i have to increment an element for. my code looks like this:
while(!infile.eof())
{
location = search(starNames, target, numStars);
if(location != -1)
if(signal >= hvalues[location] || signal <= lvalues[location])
for(int i = 0; i < MAX; i++)
{
anomalies[location] = tot +1;
}
else
cout<<"Star doesn't exist." <<endl;
getline(infile, target);
infile >> signal;
infile.ignore(256,'\n');
}
the search function will produce the index of the target in the starNames array(location). it will check to see if the signal is in the correct range and if it is, will add one to the corresponding element in the anomalies array. however i can't get it to total up the anomalies and increment correctly.
another question i have is how to add all of the elements in an array together and output that answer. this seems really simple but i seem to be getting errors that i shouldn't be. this is my function i have so far:
int findtotal(string anomalies[], int& numStars)
{
int total = 0;
int tot = 0;
numStars = 5;
for(int i =0;i<numStars;i++){
anomalies[i] = tot + tot;
total= tot;
}
return total;
}
i am not sure if this is right because i get an error in the call from main:
int total;
total = findtotal(anomalies, numStars);
saying it can't convert a int to a string or something but the anomalies array is all ints.
please help.
the first one i am trying to calculate how many times something happens and increment an element in array each time that happens. this is for multiple objects that i have to increment an element for. my code looks like this:
while(!infile.eof())
{
location = search(starNames, target, numStars);
if(location != -1)
if(signal >= hvalues[location] || signal <= lvalues[location])
for(int i = 0; i < MAX; i++)
{
anomalies[location] = tot +1;
}
else
cout<<"Star doesn't exist." <<endl;
getline(infile, target);
infile >> signal;
infile.ignore(256,'\n');
}
the search function will produce the index of the target in the starNames array(location). it will check to see if the signal is in the correct range and if it is, will add one to the corresponding element in the anomalies array. however i can't get it to total up the anomalies and increment correctly.
another question i have is how to add all of the elements in an array together and output that answer. this seems really simple but i seem to be getting errors that i shouldn't be. this is my function i have so far:
int findtotal(string anomalies[], int& numStars)
{
int total = 0;
int tot = 0;
numStars = 5;
for(int i =0;i<numStars;i++){
anomalies[i] = tot + tot;
total= tot;
}
return total;
}
i am not sure if this is right because i get an error in the call from main:
int total;
total = findtotal(anomalies, numStars);
saying it can't convert a int to a string or something but the anomalies array is all ints.
please help.