there variable in program controls whether or not user repeat program called "done." if done = '0', program repeats; if done = '1', program exits. if user enters value other '0' or '1', enters loop prompts them enter valid until do. problem enters loop (infinitely) regardless of user enters.
the code concerned starts on line 63; here full .adb file:
with ada.text_io; use ada.text_io; ada.strings.bounded; unchecked_conversion; stack; procedure main package int_io new ada.text_io.integer_io(integer); stack_type : positive; stack_size : natural; begin loop -- select stack type put_line("select stack type inputting corresponding number: "); put_line("1) character"); put_line("2) integer"); put_line("3) date"); int_io.get(stack_type); -- select size of stack put_line("enter maximum size of stack: "); int_io.get(stack_size); case (stack_type) -- character stack (option c/d) when 1 => declare package char_stack new stack(stack_size, character); use char_stack; char : character; done : integer := 0; num_chars : natural := 48; -- 48 = ascii '0' -- reflects how many characters (including number) of name on top of stack; used limit in popping loop num_to_pop : natural := 0; -- pop , print characters stack procedure print_chars begin in 0 .. (num_to_pop - 1) loop put(char_stack.pop); end loop; -- reset num_to_pop num_to_pop := 0; end print_chars; begin put_line("enter characters; finish sequence, terminate '#': "); new_line; while (done /= 1) loop while (char /= '#') loop get(char); if (char /= '#') push(char); num_chars := num_chars + 1; end if; end loop; -- push number of characters onto stack; reset num_to_pop; reset num_chars push(character'val(num_chars)); num_to_pop := (character'pos(peek)) - 47; num_chars := 48; -- ask user if wish continue new_line; put_line("to repeat, enter '0'; terminate program, enter '1': "); new_line; int_io.get(done); -------------test---------------- new_line; int_io.put(done); new_line; --------------------------------- while (done /= 0 or done /= 1) loop put_line("please enter either '0' or '1'."); new_line; int_io.get(done); end loop; end loop; end; -- integer stack (option b) when 2 => begin put("asfsf"); -- end; -- date stack (option a) when 3 => begin put("asfasdf"); -- end; when others => begin put("asdfasdf"); end; end case; end loop; end main;
you write
while (done /= 0 or done /= 1) loop
but should have written
while (done /= 0 , done /= 1) loop
or even, since ada doesn’t need parentheses here,
while done /= 0 , done /= 1 loop
or, applying de morgan’s law,
while not (done = 0 or done = 1) loop
Comments
Post a Comment