This post has been edited by Ipodhero178: 27 June 2012 - 03:19 PM
Program Design Question
Page 1 of 13 Replies - 1613 Views - Last Post: 19 July 2012 - 10:38 AM
#1
Program Design Question
Posted 27 June 2012 - 10:10 AM
I am working on a personal project that uses a data structure to store data the user inputs. Once I calculate the average, I pass the average to another page where it is displayed for the user. I noticed that if the user goes back to the previous screen, the previous input stored within the data structure is still present and new input will be added to the previous data, which is not what I want. I wanted to know if it would be okay from a designer's standpoint to try and wipe the previous data after I get the average but before I move the average to another page. If not, what is the proper way in terms of programming design to solve my issue? Thank you very much for the help.
Replies To: Program Design Question
#2
Re: Program Design Question
Posted 29 June 2012 - 12:14 PM
If you don't need to remember the last input then don't add it to your data struct just use a function to return the average of the data struct and that input.
for example assuming you data struct is an array of values.
Just pass the return value of average() to the new page. This way you're not maintaining unneeded state.
for example assuming you data struct is an array of values.
float function average(dataStruct, input) {
var total = input;
for (int i=0; i < dataStruct.length; i++) {
total += dataStruct[i];
}
return (input/total);
}
Just pass the return value of average() to the new page. This way you're not maintaining unneeded state.
#3
Re: Program Design Question
Posted 29 June 2012 - 11:52 PM
shintetsu_80, on 29 June 2012 - 01:14 PM, said:
If you don't need to remember the last input then don't add it to your data struct just use a function to return the average of the data struct and that input.
for example assuming you data struct is an array of values.
Just pass the return value of average() to the new page. This way you're not maintaining unneeded state.
for example assuming you data struct is an array of values.
float function average(dataStruct, input) {
var total = input;
for (int i=0; i < dataStruct.length; i++) {
total += dataStruct[i];
}
return (input/total);
}
Just pass the return value of average() to the new page. This way you're not maintaining unneeded state.
Wouldn't the data structure still be instantiated and therefore, would still hold the values given by the user? If they go back after getting their first average, wouldn't the problem remain? There is still data within the data structure even if I send it to that method.
This post has been edited by Ipodhero178: 30 June 2012 - 01:57 PM
#4
Re: Program Design Question
Posted 19 July 2012 - 10:38 AM
My understanding from the description of the problem was that the data struct would be fixed and the user would not be specifically adding data to that struct. So only the single input would be averaged with the static values in that struct.
If it's the case that all the data is entered by the user then similarly don't store anything. Just have one function that returns the average of all the values after the user is done entering them.
You'll need to provide some code or example of how you're trying to do what you want. In the end the generic answer is you can do it however you want if it works for you.
If it's the case that all the data is entered by the user then similarly don't store anything. Just have one function that returns the average of all the values after the user is done entering them.
You'll need to provide some code or example of how you're trying to do what you want. In the end the generic answer is you can do it however you want if it works for you.
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote



|