1 2 3
|
while (userInput < 1) {
static float *scores = getScore();
|
I think this may be your problem.
Declaring a local variable as "static" means it will be initialised only once, at the point of definition, and then retain it's value unless it is explicitly changed.
So if you had a function:
1 2 3 4 5
|
int getSin(int angle)
{
static int ret = sin(angle);
return ret;
};
|
getSin() would initialise ret the first time you call it, thereafter, the value of get remains the same, and the line
static int ret = sin(angle);
never gets executed again.
From that, you can see that your line
static float *scores = getScore();
will only be called once, so you never in fact try to get new values from the user, on subsequent iterations of your
while (userInput < 1)
loop.
If for some reason you want to stick with the "static" approach (I see you're trying to avoid returning a pointer to a variable which would have been cleaned off the stack, but you don't need it to be static in main(), besides there are much better idioms for accomplishing this), then you'll have to split your declaration/definition into 2 distinct steps:
1 2
|
static float *scores = 0;
scores = getScore();
|
Given the structure of your code, consider creating the array of scores in main() and passing it's address to getScores().
Better yet, learn about the standard library containers, and use a suitable one (suggest vector<> or array<>).
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
|
#include <iostream>
#include <array>
using namespace std;
void gett(array<int, 7> &scores)
{
for (int i = 0; i < 7; ++i)
{
// get user input here
scores[i] += i;
}
}
int main()
{
// fixed-size array with magic number
array<int, 7> scores = {0};
for (int i = 0; i < 10; ++i)
{
gett(scores);
for (int j = 0; j < 7; ++j)
{
cerr << scores[j] << "\t";
}
cout << endl;
}
return 0;
}
|