I am writing code for a car rental system but i'm getting a few compile error messages that don't understand.
The first error is
TypeError: Expression has to be an lvalue.
The second is
TypeError: Type address is not implicitly convertible to expected type function () view external returns (address).
The third is
TypeError: Operator < not compatible with types uint256 and function () view external returns (uint256).
Here's my code:
PLEASE NOTE: The asterisk represents which line in the code errors.
pragma solidity ^0.4.18;
contract rentCar {
struct Renter {
address addr;
uint DOB;
uint currentRenting;
}
bool public rented;
address public owner;
uint public duration;
uint public rentalPrice;
uint public charge;
uint public rentalDate;
uint public returnDate;
uint public rentalStartDate;
uint public rentalEndDate;
uint public constant totalDays = 7;
struct NameKey{ // storage the name's keys
uint[] keys;
}
//List of Cars available
uint[] private ids; //Use it to return the ids of Objects
uint public numofCars;
mapping(uint => Car) private cars;
mapping(string => NameKey) private nameToKeys;
//Events
event E_addCar(uint objID, address VechileOwner);
event E_Rent(address indexed _renter, uint _rentalDate, uint _returnDate, uint _rentalPrice);
event E_ReturnRental(address indexed _renter, uint _returnDate);
//Modifiers
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/*
modifier onlyRenter() {
require(msg.sender == addr);
_;
}
*/
modifier whenNotRented() {
require(!rented);
_;
}
modifier whenRented() {
require(rented);
_;
}
//Funcions
function rentCar() public{
owner = msg.sender;
}
function addCar(string make, string model, uint pricePerDay, uint minRentalDay, uint maxRentalDay, bool available) public onlyOwner {
Car newCar = cars[numofCars];
///nameToKeys[name].keys.push(numofCars); //add the key to the name's keys
///***ERRORS
newCar.VechileOwner = msg.sender;
newCar.make = make;
newCar.model = model;
newCar.available = available;
newCar.pricePerDay = pricePerDay;
newCar.minRentalDay = minRentalDay;
newCar.maxRentalDay = maxRentalDay;
newCar(numofCars,msg.sender);
ids.push(numofCars);
numofCars++;
}
function setAvailable(uint objID, bool _available) public view onlyOwner {
///***ERRORS
cars[objID].available = _available;
}
/* function totalDays (uint rentalStartDate, uint rentalEndDate) public whenNotRented{
uint totalDays = ;
return totalDays;
}*/
function Rent(uint objID,uint totalDays) public payable whenNotRented returns(bool){
///***ERRORS
require (msg.value < cars[objID].deposit);
require(totalDays >= cars[objID].minRentalDay && totalDays <= cars[objID].maxRentalDay);
cars[objID].renter = Renter({addr:msg.sender, currentRenting:now});
uint PayDeposit = msg.value - cars[objID].deposit;
rentalPrice = totalDays * cars[objID].pricePerDay;
rentalDate = rentalStartDate;
returnDate = rentalEndDate;
cars[objID].available = false;
rented = true;
// accessCar();
///***ERRORS
E_Rent(Renter, rentalDate, returnDate, rentalPrice);
return true;
}
function endRent (uint objID, uint duration) public whenRented {
///***ERRORS
duration = (now - cars[objID].renter.currentRenting) / (24*60*60*1.0);
charge = duration * cars[objID].priceDaily - cars[objID].deposit;
uint totalPayment = msg.value - charge;
require(!cars[objID].VechileOwner.send(charge));
require(!cars[objID].renter.addr.send(charge));
delete cars[objID].renter;
cars[objID].available = false;
E_ReturnRental(Renter, now);
resetRental();
}
function forceRentalEnd() public onlyOwner{
require(now > returnDate && rented);
E_ReturnRental(Renter, now);
resetRental();
}
function resetRental() private{
rented = false;
Renter.addr = address(0);
rentalDate = 0;
returnDate = 0;
}
}
I have a second contract called Car that interacts with the other contract
contract Car is rentCar {
address public VechileOwner;
string public make;
string public model;
Renter public renter;
bool public available;
uint public pricePerDay;
uint public deposit;
uint public entrycode;
uint public minRentalDay;
uint public maxRentalDay;
function checkAvailability() public view returns (bool) {
return(Car.available);
}
function Car(string _make, string _model, uint _pricePerDay, uint _minRentalDay, uint _maxRentalDay, bool _available) public onlyOwner{
make = _make;
model = _model;
pricePerDay = _pricePerDay;
minRentalDay = _minRentalDay;
maxRentalDay = _maxRentalDay;
available = _available;
}
}
I'd really appreciate the help.
Here are the error messages that appear on remix:
Many thanks
Car
definition andresetRental()
function. Can you split your contract into smaller parts so it is easier to test and verify your error messages?*
in the errors with comments///***ERRORS
so they don't cause syntax errors. Check if you think is something is wrong.