Reservation Summary
Part of the Fundamentals section of Coddy's Solidity journey. Lesson 53 of 53.
Challenge
HardDefine struct Booking with uint256 capacity and uint256 reserved. Initialize a memory Booking using the first two inputs. Use an internal pure helper to decide whether requested fits in the remaining capacity. If it fits, add requested to reserved. Print the decision, final reserved count and remaining capacity. The initial reserved count never exceeds capacity.
The tests pass arguments to main in this order: uint256 capacity, uint256 reserved, uint256 requested. Each test starts with fresh contract state.
Use console.log for the requested output. Print only the requested values, one per line, with no extra labels unless the task specifies them.
Try it yourself
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "forge-std/console.sol";
contract Main {
function main(uint256 capacity, uint256 reserved, uint256 requested) external view {
// Write your solution here.
}
}All lessons in Fundamentals
Practice on your own: Solidity playground