-2

I want to know how to set the length for the input and also how to get the size of the string that is entered by the user.

For example, they might enter 9 or 99 to represent the number of tickets they want to buy, but I do not want to limit them to enter 2 digits every time like 09 for singular, I want that they can enter 9$ or 99$. After that based on the length of the input, the number will be treated as different values, if the input is only 1 digit then the first digit will be represented as one, if the input is a 2 digit input then the first digit will represent tens.

After that I will multiply using the formulae of:

Total = 1.5 * number of stops traveled * number of ticket * 105%

How do I perform the calculation?

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
Chin
  • 97
  • 2
  • 9
  • 2
    Which part is causing you problem? Just process the input characters one by one. Stop at the `$` sign or if you hit end of input (or an invalid digit). – Jester Sep 02 '21 at 23:40
  • No the $ actually just for me to represent the user pressing enter key. I have the idea about it but do not know how to code it out. I want it to be like, user type in 1-9 then press enter if they buying 1 to 9 ticket or XX(99) if they buying more than 9 tickets, for example, 10. – Chin Sep 03 '21 at 01:52

2 Answers2

1

I want to know how to set the length for the input and also how to get the size of the string that is entered by the user.

The easiest would be to use the DOS.BufferedInput function 0Ah. You can read about it in How buffered input works.

set the length

You seem to expect user input that has 1 or 2 digits. Then a buffer with 3 bytes is fine; room for at most 2 characters and a terminating carriage return.

INBUF  db 3, 0, 3 dup (0)

You use it like:

lea dx, INBUF         
mov ah, 0Ah  
int 21h

get the size

This is how you read the length of the inputted text:

mov cl, [INBUF + 1]
mov ch, 0                ; -> CX is either 1 or 2

Assuming the user inputs 5 enter, then from the code above the CX register would hold 1. You then convert the character "5" into the value 5 by subtracting 48, like in:

mov al, [INBUF + 2]
sub al, 48

Total = 1.5 * number of stops traveled * number of ticket * 105%

How do I perform the calculation?

That's a whole different question for which you should show us your best effort. I think that with the help of today's answer, you should be able to start working on that...

One tip though: don't let the decimal point fool you, you can calculate this entirely using integer instructions.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
0

From the tag x86-16 I assume that you want your program run in DOS.

You can use DOS function READ FROM FILE OR DEVICE. Set the file handle to BX=0 ; Standard input handle, specifiy the buffer size in register CX and invoke the function.
Number of characters, which the user has actually entered, is then returned in register AX.

vitsoft
  • 5,515
  • 1
  • 18
  • 31