如何在Delphi 10.3上的字符串中不接受特殊字符

问题描述 投票:0回答:1

我正在尝试为学校的作业编写程序。它应该接受姓名作为string,并输入薪水作为integer,并告诉您您是否模糊不清或能够参加聚会,然后重复直到stop=9

一切顺利,但是问题是string变量接受错误的名称作为输入并继续。例如'John32@#$^^'

我希望程序不接受这些输入,并写一行,说明它将不以任何名称(除了字符之外)继续。这也不应添加要停止的数字。源代码如下。

program Sba;

Uses
  Windows;

var
  FName,LName:String;
  Stop,Salary:Integer;

//procedure Sleep(milliseconds: Cardinal); stdcall; external 'kernel32.dll'; //Added sleep as a procedure for delay

Begin
  Repeat //Repeats until stop = 9
    Writeln('Hi User,please Enter your First Name'); //Prompting user to enter their First initials
    Readln(FName); //Attaches the string entered to the variable FName
    Sleep(1000);//Delay 1second
    Writeln('First Name entered');  //Lets the user know they have entered their first initials
    Sleep(1000);
    Writeln('Please Enter your Last name'); //Prompting user to enter their last initial
    Readln(LName);  //Attaches the string entered to the variable LName
    Sleep(1000);
    Writeln('Last Name entered'); //Lets the user know they have entered their last initials
    Sleep(800);
    Writeln('Hi ',' ',FName,' ',LName); //Writes Line Hi (First Name) (Last Name)
    Sleep(1000);
    Writeln('Please enter The amount you have paid');//Prompts user for their payment
    Readln(Salary); //Atttached value entered to Salary
    Writeln('Reading your payment will be done in four seconds');
    Sleep(4000);//delay 4 seconds
    Writeln('Done!');
    If (Salary<1000) Then
    Begin
      Writeln('You do not have sufficient funds to play in a section');
    Sleep(1000);
    End;
    Sleep(1000);
    If (Salary>=1000) AND (Salary<=2000) then //Testing conditions
    Begin
      Sleep(1000);
      Writeln('Congrats, You are eligible to play in the Tribe Section'); //Tells use what section they are available to play in
    End;
    If (Salary>=2100) AND (Salary<=3000) then //Testing conditions
    Begin
      Sleep(1000);
      Writeln('Congrats, You are eligible to play in the Poison Section');
    End;
    If (Salary>=3100) AND (Salary<=5000) then //Testing conditions
    Begin
      Sleep(1000);
      Writeln('Congrats, You are eligible to play in the Harts Section');
    End;
    Writeln('Press enter to continue');
    Readln;
    Writeln('Enjoy your day ' , FName,'!');
    Stop:=Stop+1; //Repeats until stop= 9
    Sleep(1000);
  Until Stop=9;//Repeats this 10 times
  Writeln('Written By Timothy Adams 4-1');
  Readln;
end.
string delphi variables pascal
1个回答
2
投票

由于这是家庭作业,因此我不会完全给您您要的东西。相反,我将为您提供更多涉及的示例进行研究。

© www.soinside.com 2019 - 2024. All rights reserved.