problem with inserting in an array code #5233
Closed
jeevansiddu
started this conversation in
General
Replies: 2 comments
-
Hello @jeevansiddu, first you need to declare uint256[] public percentage; This syntax will create an empty The way you have it you are trying to access and update a value that does not exist yet. You can append values to function calculatepercentage() public {
// the array is empty, this doesn't work
// for(uint i=0;i<15;i++){
// percentage[i]=(amountfunded[i]*1000)/total;
// }
// append the values
for(uint256 i=0; i < 15; i++) {
percentage.push((amountfunded[i] * 1000) / total);
}
// uint256 z=0;
// percentage=(10*1000)/100;
// return (10*1000)/100;
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
ohh thank you so much it worked , I totally forgot about the push method 🫡 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I try to calculate percentage for my
this code below works
correctly in percentage the value 100 is stored , but when i convert that percentage array var into an object it throws an error
it throws ann error like
can someone tell why it is happening
Beta Was this translation helpful? Give feedback.
All reactions