0

i am new to programming, can any one help me to understand how to map the order number and the table number in a hotel contact, i tryed up to map both order and table but not able to get the proper linkage for both and out put as order 2 table number 1.

and adding items to a particular order as order1"item 1- Dosa, Qty2, item-2 idly Qty 1"

below is my source code.

pragma solidity ^0.5.0;

contract Menu{
    uint256 public BookingId;
    address public Guest;
    uint256 Qty;
    
    struct Menuitem{
        uint256  id;
        string name;
        uint256 Price;
    }
    struct table{
        uint256 tableid;
        uint256 numberofseats;
    }
      mapping (uint256 => Menuitem) public Order;
      mapping (uint256  =>mapping(uint256 => Menuitem)) public tableno;
      Menuitem[] itemarray;
      table[5] tablearray;
     
      
      function welcome() public {
          log0("welcome");   /*need to ask*/
      }
      
      function additem(uint256 _id, string memory _name, uint256 _price) public{
          
        Menuitem memory newitem = Menuitem(_id, _name, _price);
        Order[_id] = newitem;
        itemarray.push(newitem);
        Qty++;
      }
      function itemcount() public view returns(uint256){
          return Qty;
      }
      function deleteitem(uint256 _id) public{
          delete Order[_id];
          Qty--;
      }
     
      
      function getItem(uint256 _id) view public returns (string memory _name, uint256 _price) {   
         return(Order[_id].name, Order[_id].Price);
    }
}

Regards, Naresh

  • It is not clear what do you want to achieve. Can you add more details? Also the code assign newitem to a mapping and an array creating two unrelated copies, that is a bug unless you really want two copies. – Ismael Jun 21 at 8:11
  • HI, thanks for taking time for go thru, basically i am trying to write a code for a hotel by using mapping to menu, order and the table to reserve. and when i try to write a code i can able to push an item to menu by taking new item as Variable but i am not able to create a order by taking the items from same menu, of-course the code is incomplete. – naresh Jun 21 at 13:24
  • We can help you with the solidity part, but we can't solve for you the relationship of menu, order and table. How these are related? What do you expect to be able to do? Edit your question to add examples of menu, order and table. – Ismael Jun 21 at 15:54
  • example: i have 50 items in menu(struct for menu create), from menu i can take 2 items(mapping with menu and order with item ID and qty) once ordered we will get the order number, for the particular order number need a table to be reserved or served, so the order taking and serving need to know the details of order and bill will be supplier to that particular ordered table . – naresh Jun 21 at 16:07
  • Hi Ismael, i have modified the if you can share your mail id, i will send code. – naresh Jun 23 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.