Question

Ok, this question may sound ambiguous, but i literally dont have another way how to put it. Hopefully explaining it will help you guys figure out what i mean..

I've recently decided to retake Pascal programming language. I did some Delphi a few years ago, but i really didnt like it. Anyway, enough of this background..

I was asked to do a simple console calculator. As of right now, i have the whole "interface" set out. It wont be reading values based on position/enter key yet, so im refraining to typing the values and using the math operators (+,-,*,div [since i've learned that "/" doesnt work well for divisions) in between the values.

My question here is:

Im reading the value using the console readln(variable) command. It works as its supposed to, but now i want to, em, play with it a little bit. I was wondering if there was a way for me the break the readln() sentence when i hit the '+,-,/,*' keys. Like, for example, i have this line:

readln(value1)

What i want to do is that, i'd type anything and the program will store it in the value1 variable up until the point when i hit one of the operators key (+ for example). It'd be something like this:

readnln(value1);
***break it when i hit one of the operators key, '+' for example***
readln(operator)
***break it right after i type the operator, so this would take just one char***
readln(value2)
***This one can be break with the "enter" key hit, so nothing needed here***

This any of this make sense? I really hope it does.

Was it helpful?

Solution

You can't do this (easily) with readln, you need to craft this yourself on to of read(c) with c: char. (or better, crt.readkey)

For a fancy version of that principle, see inputstr in the "gameunit" in the FPC demoes, used to input names in the tetris demo's high score.

See also the "lister" demo that demonstrates a lot of small textmode techniques.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top