1
{ return studentStructs [user].books[raw]; } 

// Type string memory is not implicitly convertible to expected type uint256.

2 Answers 2

1

To be honest, you question isn't very clear, and I'm not exactly sure what you're asking, but I have written a basic smart contract, which I hope can help.

// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; contract Enums { struct User { Book book; } enum Book { Book1, Book2, Book3 } mapping(address => User) public students; function setStudentBook(Book _book) external { students[msg.sender].book = _book; } function getStudentBook() external view returns (string memory) { uint8 book = uint8(students[msg.sender].book); if (book == 0) { return "Book1"; } else if (book == 1) { return "Book2"; } return "Book3"; } } 

You'll notice that depending on which value has been set in the setStudentBook() function, the string return value for the getStudentBook() function will reflect the enum value.

I hope this answers your question.

1

unable to understand your problem but as @brendon Richards write code, this is quite clear example of usage of enum. because in enum return, it always return number but it depends on you how you use this numbers in your logic. If you have any ambiguity you can ask

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.