module sale( input clk , input rst_n , input sel ,//sel=0,5$dranks,sel=1,10&=$drinks input [1:0] din ,//din=1,input 5$,din=2,input 10$ output reg [1:0] drinks_out,//drinks_out=1,output 5$ drinks,drinks_out=2,output 10$ drinks output reg change_out ); parameter s0=0,s1=1; reg[2:0] next_state,state; always @(*) begin case (state) s0 : next_state= sel ? (din==1 ? s1:s0) : s0; s1 : next_state = din==0 ? s1 : s0; endcase end always @(posedge clk or negedge rst_n) begin if(!rst_n) begin state<=s0; end else begin state<=next_state; end end always @ (posedge clk or negedge rst_n) begin if(!rst_n) begin drinks_out<=0; change_out<=0; end else if (sel) begin change_out<= (state==s1 && din==2); drinks_out<= ((state==s1 && (din==2|| din==1)) || din==2) ? 2:0; end else begin change_out<= din==2; drinks_out<= (din==1 || din==2) ? 1:0; end end endmodule