0

I'm trying to run my code but I get this error:

Could not compile the source code.

Undeclared identifier. require(available); ^-------^ However, I defined 'available' as a boolean in a struct

struct Car{
  address  VechileOwner;
  string make;
  string model;
  Renter renter;
  bool available;
  uint pricePerDay;
  uint deposit;
  uint entrycode;
  uint minRentalDay;
  uint maxRentalDay;
 }

Much Appreciated.

0

The correct way to use variable (or boolean) inside the struct in example:

pragma solidity ^0.4.18;

contract Car {

    struct car {
      bool available;
    }

    car audi;

    function Car() public {
        audi = car(true);
    }

    function checkAvailability() public view returns (bool) {
        return(audi.available);
    }
}

As you can see, you cannot just use require(available);; you need to assign the struct as some_name and then use require(some_name.available).

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.