//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.4.18; contract CarRental { address public owner; uint256 public rentalPrice; mapping(address => uint256) public deposits; struct Car { string name; bool available; } mapping(uint256 => Car) public cars; event CarRegistered(uint256 carId, string name); event CarRented(uint256 carId, address renter, uint256 deposit); event CarReturned(uint256 carId, address renter); modifier onlyOwner() { require(msg.sender == owner); _; } function CarRental(uint256 _rentalPrice) public { owner = msg.sender; rentalPrice = _rentalPrice; } function registerCar(uint256 _carId, string _name) external onlyOwner { cars[_carId] = Car(_name, true); emit CarRegistered(_carId, _name); } function rentCar(uint256 _carId) external payable { require(cars[_carId].available); require(msg.value == rentalPrice); cars[_carId].available = false; deposits[msg.sender] += msg.value; emit CarRented(_carId, msg.sender, msg.value); } function returnCar(uint256 _carId) external { require(!cars[_carId].available); require(msg.sender == owner); cars[_carId].available = true; address renter = msg.sender; uint256 depositAmount = deposits[renter]; deposits[renter] = 0; renter.transfer(depositAmount); emit CarReturned(_carId, msg.sender); } }
0.4.18