Hi, I cant figure out how to get the years 298,299,300 each, one time. everytime i do i get 298,299,299. i am passing arrays and struct arrays. Let me me know if you need anymore info.
// header file
void determineBattPerYear(BattlesPerYear numbBat[], int year[]);Paste
string Write( BattlesPerYear numbBat[]);
//struct
struct BattlesPerYear {
int battles;
int year;
};
int main(){
charint SIZE= 9;
int year[SIZE] = {298,298,298,298,299,299,300,300,300};
battlesPerYear numbBat[SIZE];
determineBattPerYear(numbBat, year)
Write( numbBat);
}
// Here I am trying to loop thru each size of each year at i and if the year doesint = its self than the year at h is = to the year at i.
determineBattPerYear(numbBat, int year[]){
numbBat[0].year = year[0];
for (int i = 1; i < SIZE; i++) {
for (int h = 1; h < 3; h++) {
if (year[i] != year[i-1]) {
numbBat[h].year = year[i - 1];
}
if (year[i] != year[i]) {
numbBat[h].year = year[i];
}
}
// here I am storing the info in a string stream
string Write(Battles battles[], BattlesPerYear numbBat[]) {
stringstream ss;
string output;
for (int i = 0; i < 3; i++) {
ss << "Year, " << numbBat[i].year << endl;
}
output = ss.str();
return output;
}
I can't make much sense of your code, but one of these ideas might help you...
for(year = 298; year <= 300; year++)
do something
or
for(i = 0; i < size; i++)
dostuffwith(year[i]);
i see you looping from 1 to < size, but its 0 in c++ not 1
but you are also doing some sort of -1 backtracking. I can't tell if you know what you are doing or not. It could be correct to start with 1.
battlesPerYear numbBat[SIZE]; //your struct is not spelled the same. c++ cares about case.