We help IT Professionals succeed at work.

struggling with scores

rosebud11
rosebud11 asked
on
I am trying to write a program where there are 4 people entering their scores which are between 0 and 26 after each person has entered their score a running total is kept when one of the people reach 100 the game is over. I can so far get it to get the 4 peoples first numbers but if a person enters a number below 0 or above 26 i have a problem say it was person number 3 who entered 45 it will go straight on to person number 4 instead of returning to person number 3 i think i need a repeat inorder for the program to continue till someone reaches 100 im lost with it now can some one help

here is a copy of what i have done so far
program scores;
{Program      : scores                     }
{Author       : Linda Paterson             }
{Date         : 22/October 2001            }
{Description  : A program which keeps score}
{of 4 players totals and keeps a running   }
{total when 100 reached player wins and all}
{scores are displayed                      }

uses
    crt;

type
    player_array = array [1..4] of string;
    score_array = array [1..4] of integer;
var
   player : player_array;
   scores : score_array;

procedure input_scores(var scores : score_array);
var
   count : integer;
begin
    for count := 1 to 4 do
    begin
         write('Enter score : ');
         readln(scores[count]);
         if (scores[count] < 0) or (scores[count] >= 26) then
            writeln('Enter a number between 0 and 26');
    end;
end;

procedure check_scores(var scores : score_array);
begin
end;

procedure display_scores(var scores : score_array);
begin
end;

begin
clrscr;
input_scores(scores);
end.
Comment
Watch Question

Your problem is fairly simple.
You're reading a string not a number.
The readln must take a string then convert it (using val()) to a number.

Also is 26 a good number?  If so, your program won't allow it (minor modification).

A cheap trick to keep the thing from going to 4 is to subtract one from it in case you do not get the proper value entered.   Another way is to use a while loop and increment only when you get good numbers.

I could write this for you, but it's a violation of EE's policy.
also...
my compiler complained about the use of 'scores' for two different things (the program name and a data type).
Quid, Me Anxius Sum?  Illegitimi non carborundum.
CERTIFIED EXPERT
Commented:
procedure input_scores(var scores : score_array);
                     var
                       count : integer;
                     begin
                        for count := 1 to 4 do
                        begin
                             write('Enter score : ');
                             readln(scores[count]);
******
                            while ((scores[count] < 0) or (scores[count] >= 26))   do  
                                      begin
                                         writeln('Enter a number between 0 and 26');
                                         writeln('Enter score');
                                         readln(scores[count]);
                                     end;
********
                        end;
                     end;


Try the bit between the **** in your code
My name is MudSystems Engineer

Commented:

write('Enter score : ');
readln(scores[count]);
if (scores[count] < 0) or (scores[count] >= 26) then
  writeln('Enter a number between 0 and 26');



Change this to...

Repeat
  write('Enter score : ');
  readln(scores[count]);
Until (Scores[Count] >= 0) and (Scores[Count] <=26);
My name is MudSystems Engineer

Commented:
WAIT WAIT...

DAMN... I'M SORRY dbrunton I didn't saw your answer...


Rosebud11: DBrunton comment is a good answer... I didn't saw it, and post mine as an answer... feel free to reject... and assign it to DBrunton...


Sorry people...
dbruntonQuid, Me Anxius Sum?  Illegitimi non carborundum.
CERTIFIED EXPERT

Commented:
No problem.

Do it occasionally  myself.

Author

Commented:
Thanks dbrunton want to accept your answer how do i accept your answer cant remember its that long since i used this

Author

Commented:
Sorry wanted to accept dbruntons answer as it was first and it worked great thanks anyway

Author

Commented:

Explore More ContentExplore courses, solutions, and other research materials related to this topic.