I am a new student in programming and having problems in writing a game where the user will input a word, character or munber values for processing.

I will be grateful for the assistance.

Thank you.

Edward :)

Dani AI

Generated

A few practical notes that build on ’s starter example and the later request from for a Deal-or-No-Deal structure. The usual pitfalls are: (1) leftover newline/input buffering when reading single characters, (2) compiler differences (classic Turbo/Free Pascal vs Delphi), and (3) ambiguous numeric formats (leading sign, decimal point, exponent). A small helper that classifies a trimmed line is often the simplest foundation for both small demos and bigger text-driven games.

function ClassifyInput(const s: string): string;
var
  t: string;
  code: integer;
  iVal: longint;
  rVal: real;
begin
  t := s;
  while (Length(t) > 0) and (t[1] = ' ') do Delete(t,1,1);
  while (Length(t) > 0) and (t[Length(t)] = ' ') do Delete(t,Length(t),1);
  if t = '' then Exit('empty');
  if Length(t) = 1 then
    if t[1] in ['0'..'9'] then Exit('digit') else Exit('char');
  Val(t, iVal, code); if code = 0 then Exit('integer');
  Val(t, rVal, code); if code = 0 then Exit('real');
  Exit('word');
end;

Use the classifier inside an input loop to validate and reprompt instead of accepting the first bad value. For single-key choices consider Read or the Crt unit’s ReadKey (no newline) depending on the target compiler. When parsing numbers for game logic, prefer typed conversions with error checks (like Val shown above) rather than ad-hoc character tests — it avoids corner cases.

For a Deal-or-No-Deal prototype (as asked by ): model boxes as an array of records (value, opened flag), shuffle values at start, let the player pick and open, and compute banker offers from the mean of remaining values adjusted by a difficulty multiplier. Keep I/O, game state and banker math in separate procedures to make the program easier to extend and debug.

Recommended Answers

All 5 Replies

Very basic but should get you started...

program game;
uses
   SysUtils;
var
   UserInput: string;
   Number: Double;
begin
   UserInput := '';
   
   Write('Enter a word, character, or number: ');
   Readln(UserInput);
   
   if TryStrToFloat(UserInput, Number) then
   begin
      WriteLn('User entered a number.');
   end
   else if Length(UserInput) = 1 then
   begin
      WriteLn('User entered a character.');
   end
   else
   begin
      WriteLn('User entered a word.');
   end;
end.

Hello Jackrabbit,

Thank you so much for the assistance.

I am trying to study what you have sent me and hope to be successful.

Thanx

Edward

hi
i am having trouble programming a game in Pascal (Deal or no Deal)
so your help would be greatly appreciated!
thank you :)

i'm not sure why you're opening threads since 2005?

create a new thread, post your code, what you can not accomplish and somebody will help you

best regards,

Look to my webpage
http://www.trsek.com/en/hry/10

Zdeno Sekerak

I am a new student in programming and having problems in writing a game where the user will input a word, character or munber values for processing.

I will be grateful for the assistance.

Thank you.

Edward :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.