0

I am trying to declare array of structure but its not accepting. I got this program from internet.

    pragma solidity ^0.5.1;
      contract NaiveBank { 
      struct Account { 
         address addr ;
        uint balance ; 
      } 
      Account accounts []; 
      function applyInterest () returns ( uint ) { 
         for ( uint i = 0; i < accounts . length ; i++) { 
            // apply 5 percent interest 
            accounts [i]. balance = accounts [i]. balance* 105 / 100; 
         } 
         return accounts . length ; 
      } 
   }

I am getting following error message:

D:\SolidityContractsSelf\Remix\From Remix Site\Struct>solc NaiveBank.sol NaiveBank.sol:8:18: Error: Expected ';' but got '[' Account accounts [];

             ^

D:>

Some body please guide me.

Zulfi.

1

Change this:

Account accounts [];

To this:

Account[] accounts;

Or better yet, to this:

Account[] public accounts;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.