Reputation: 41
I'm trying to simply change a value to an array and then to write that array to a file and save it. Here is my code:
void changePrices(float prices[15])
{
int row;
string filename = "rowPrices.dat";
ofstream inFile(filename);
cout << "Enter in the row: ";
cin >> row;
int rownumber = row - 1;
cout << "Enter in the new price: ";
float price;
cin >> price;
cout << price << endl;
price = prices[rownumber];
for (int i = 0; i < rowvalue; i++)
{
inFile << prices[i] << endl;
}
cout << prices[rownumber];
ifstream save(filename);
}
However, my price
variable is not being written to the array value (in this case prices[rownumber]
). I simply try to assign the floating variable to the array, but it simply is not being overwritten. Additionally, I want that file to be saved using some kind of save function. Is it working properly? How can I overwrite my variable to the array value? Note: the array is a float.
Upvotes: 0
Views: 341
Reputation: 6125
You're not changing the array, you are copying a value from the array to price
, effectively overwriting what the user entered.
price = prices[rownumber];
should be
prices[rownumber] = price;
Upvotes: 2