0

I'm about to build a program written in pseudocode. I've already done most of the work , but I'm stuck on the code and I don't know what to do exactly. im a begginer and not everything is clear to me ...in one of the tasks i have to do , i have to make the program ask for the players name , which will be stored as a string then the program has to check if it exceeds the limit between 2/20 characters and inform the user if the input is wrong . i have researched and tried to figure out how i might be able to fix my code but i have a really short amount of time left and coudn't find anything regarding my problem :/ . this is the code ive done for this specific task. i know its wrong but i just dont know how to fix it . any help with be much appreciated . Thanks in advance :)

pseudocode:

// Getting user's name

valid = false 
loop until valid is equal to true
     Output" please enter your name "
     Input playName
     If (playName is => 1)AND(=<20)then
Valid = true
Otherwise
output "name exceeds the character limit"
chepner
  • 497,756
  • 71
  • 530
  • 681
domingo
  • 3
  • 2

1 Answers1

0

I'm not sure what the syntax of your pseudo code is but :

  1. assuming tabulation has meaning, you may have forgot to indent some lines to include them in the loop
  2. 'valid' is first declared with a lower case first letter so you may continue referencing it same way in line "Valid = true" -> "valid = true"
  3. In the 'If' you want to test the lenght of the String and not compare the string to an int so maybe call a function length(String) that would return the length of the string or access a string.length attribute (as you wish in pseudo code)
  4. You want the playName to be superior or equal to 2 "length(playName) >= 2" and inferior or equal to 20 "length(playname) <= 20"
  5. The commonly used keyword meaning Otherwise is 'Else' as in
    IF (Condition) THEN (code) ELSE (code)

I may modify you code like this :

// Getting user's name

valid = false 
loop until valid is equal to true
    Output" please enter your name "
    Input playName
    If (length(playName) >= 2) AND (length(playName) <= 20)
    Then
    valid = true
    Else
    output "name exceeds the character limit"
SkyDream
  • 382
  • 1
  • 10
  • thanks for taking the time to review my code , your answer has solved the problem i had . i will keep in mind what you said – domingo Jul 22 '14 at 16:52