#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Need Help!! A.S.A.P!!!!


    Firstly, I'm sorry if this is not the place to ask for help, and yes, this is kinda my homework, and since I'm lost, I need help....

    This is a program I made from Pascal:

    program assingment2;
    uses crt;

    type
    Players = record
    Name : String[30];
    teamNo : Integer;
    goalScores : Integer;
    yellowCards : Integer;
    totScores : Integer;
    totCards : Integer;
    end;
    var
    Player : array[1..5] of Players;
    i : Integer;
    high : Integer;
    few : Integer;
    pName : String;
    gName : String;
    pTeam : String;
    gYellow : String;
    gTeam : String;
    teamName : String;

    procedure read;
    begin
    for i := 1 to 5 do
    begin
    write('Enter name: ');
    readln(Player[i].Name);
    writeln;
    writeln('Team Number Team Name');
    writeln(' 1 The Lions');
    writeln(' 2 Gelang Rangers');
    writeln(' 3 Jay Born United');
    writeln(' 4 Soothing Rovers');
    write('Enter team number: ');

    readln(Player[i].teamNo);

    if Player[i].teamNo = 1 then
    teamName := 'The Lions';



    if Player[i].teamNo = 2 then
    teamName := 'Gelang Rangers';



    if Player[i].teamNo = 3 then
    teamName := 'Jay Born United';



    if Player[i].teamNo = 4 then
    teamName := 'Soothing Rovers';

    writeln;

    write('Enter goal scores: ');
    readln(Player[i].goalScores);
    write('Enter number of yellow cards received: ');
    readln(Player[i].yellowCards);
    writeln;
    writeln;
    end;

    high := Player[i].goalScores;
    few := Player[i].yellowCards;
    for i := 1 to 5 do
    begin
    if Player[i].goalScores > high then
    begin
    pName := Player[i].Name;
    pTeam := teamName;
    high := Player[i].goalScores;
    end;
    end;

    for i := 1 to 5 do
    begin
    if Player[i].yellowCards < few then
    begin
    gYellow := Player[i].Name;
    gTeam := teamName;
    few := Player[i].yellowCards;
    end;
    end;
    end;

    procedure display;
    begin
    writeln('Player Name Team Name Goal Score(s) Yellow Card(s)');
    writeln('-------------------------------------------------------------------');
    for i := 1 to 5 do
    begin
    writeln(Player[i].Name,' ', teamName,
    ' ', Player[i].goalScores,
    ' ', Player[i].yellowCards);
    end;
    writeln;
    writeln('Highest Scores Detail:');
    writeln('Name: ', pName);
    writeln('Team Name: ', pTeam);
    writeln;
    writeln('Yellow Card Detail:');
    writeln('Name: ', gYellow);
    writeln('Team Name: ', gTeam);
    writeln;
    writeln('Press <ENTER> to continue.');
    readln;
    end;

    begin
    read;
    display;
    end.


    I need help:

    1. There is no error.

    2. The part where I need help is the if..else part.

    3. From the coding of teamNo, if I enter 1, it should display the statement.

    4. When I run it, all of the display are the same from the team name.

    5. If I choose 1, it should display 'The Lions' only. When I run it, the whole team name turns to 'The Lions' even when I input 2, 3, or 4.

    6. Also the same when displaying the highest and lowest.

    The display is like this:

    Player Name Team Name Goals Yellow Cards
    gaga The Lions 9 9
    haha The Lions 1 0
    jaja The Lions 5 4
    kaka The Lions 3 2
    lala The Lions 3 1


    Highest goal:
    Name: gaga
    Team: The Lions

    Lowest yellow card:
    Name: haha
    Team: The Lions

    From the array, you can see that all of team names are the same, even when I input different team no.

    I need help so badly.....
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    396
    Rep Power
    10
    Most of your issues stem from the fact that you are incorrectly using the FOR loop. The key thing to remember is that

    For I := 1 to 5 do
    begin
    statements
    end;

    executes all the begin..end enclosed statements 5 times, the first time with I equal to 1 and the last time with I equal to 5.

    So this code

    Code:
       for I := 1 to 5 do
       begin
        write('Enter name: ');
        readln(Player[i].Name);
        if Player[i].teamNo = 1 then
          teamName := 'The Lions';
        if Player[i].teamNo = 2 then
          teamName := 'Gelang Rangers';
        if Player[i].teamNo = 3 then
          teamName := 'Jay Born United';
        if Player[i].teamNo = 4 then
          teamName := 'Soothing Rovers';
        ...
       end;
    is equivalent to

    Code:
        write('Enter name: ');
        readln(Player[1].Name);
        if Player[1].teamNo = 1 then
          teamName := 'The Lions';
        if Player[1].teamNo = 2 then
          teamName := 'Gelang Rangers';
        if Player[1].teamNo = 3 then
          teamName := 'Jay Born United';
        if Player[1].teamNo = 4 then
          teamName := 'Soothing Rovers';
        write('Enter name: ');
        readln(Player[2].Name);
        if Player[2].teamNo = 1 then
          teamName := 'The Lions';
        if Player[2].teamNo = 2 then
          teamName := 'Gelang Rangers';
        if Player[2].teamNo = 3 then
          teamName := 'Jay Born United';
        if Player[2].teamNo = 4 then
          teamName := 'Soothing Rovers';
        write('Enter name: ');
        readln(Player[3].Name);
        if Player[3].teamNo = 1 then
          teamName := 'The Lions';
        if Player[3].teamNo = 2 then
          teamName := 'Gelang Rangers';
        if Player[3].teamNo = 3 then
          teamName := 'Jay Born United';
        if Player[3].teamNo = 4 then
          teamName := 'Soothing Rovers';
        write('Enter name: ');
        readln(Player[4].Name);
        if Player[4].teamNo = 1 then
          teamName := 'The Lions';
        if Player[4].teamNo = 2 then
          teamName := 'Gelang Rangers';
        if Player[4].teamNo = 3 then
          teamName := 'Jay Born United';
        if Player[4].teamNo = 4 then
          teamName := 'Soothing Rovers';
        write('Enter name: ');
        readln(Player[5].Name);
        if Player[5].teamNo = 1 then
          teamName := 'The Lions';
        if Player[5].teamNo = 2 then
          teamName := 'Gelang Rangers';
        if Player[5].teamNo = 3 then
          teamName := 'Jay Born United';
        if Player[5].teamNo = 4 then
          teamName := 'Soothing Rovers';
    Hope this give you a clue as to what code should be included WITHIN the FOR loop (executed 5 times) and which onces should execute just once.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0
    Thanks for the help and I immediately change the part that you pointed out and tried it. When I run it, there's no output at the team name. I think that part did the trick, but there's no output.
    I also tried to modified some of the coding:

    var
    ...
    pTeam: Integer;
    gTeam: Integer;
    ...
    for i := 1 to do
    begin
    if Player[i].goalScores > high then
    begin
    pName := Player[i].Name;
    pTeam := Player[i].teamNo;
    high := Player[i].goalScores;
    end;
    end;

    for i := 1 to 5 do
    begin
    if Player[i].yellowCards < few then
    begin
    gYellow := Player[i].Name;
    gTeam := Player[i].teamNo;
    few := Player[i].yellowCards;
    end;

    I only modified that part, and it gives me the team no. output, not the team name. And there's no output at the listing part.

    How should I change it?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0
    Never mind... I already solved it on my own, it was my mistake too not to realized it sooner... Here's the code:

    Code:
    program assingment2; 
    uses crt; 
    
    type 
    Players = record 
    Name : String[30]; 
    teamNo : Integer; 
    goalScores : Integer; 
    yellowCards : Integer; 
    totScores : Integer; 
    totCards : Integer; 
    teamName : String; 
    end; 
    
    var 
    Player : array[1..5] of Players; 
    i : Integer; 
    high : Integer; 
    few : Integer; 
    pName : String; 
    gName : String; 
    pTeam : String; 
    gYellow : String; 
    gTeam : String; 
    
    procedure read; 
    begin 
    
    for i := 1 to 5 do 
    
    begin 
    
    write('Enter name: '); 
    readln(Player[i].Name); 
    
    writeln; writeln('Team Number Team Name'); 
    writeln(' 1 The Lions'); 
    writeln(' 2 Gelang Rangers'); 
    writeln(' 3 Jay Born United'); 
    writeln(' 4 Soothing Rovers'); 
    write('Enter team number: '); 
    readln(Player[i].teamNo); 
    
    if Player[i].teamNo = 1 then 
    Player[i].teamName := 'The Lions'; 
    
    if Player[i].teamNo = 2 then 
    Player[i].teamName := 'Gelang Rangers'; 
    
    if Player[i].teamNo = 3 then 
    Player[i].teamName := 'Jay Born United'; 
    
    if Player[i].teamNo = 4 then 
    Player[i].teamName := 'Soothing Rovers'; 
    writeln; 
    
    write('Enter goal scores: '); 
    readln(Player[i].goalScores); 
    writeln; 
    
    write('Enter number of yellow cards received: ');
    readln(Player[i].yellowCards); 
    writeln; 
    writeln; 
    end; 
    
    high := Player[i].goalScores; 
    few := Player[i].yellowCards; 
    
    for i := 1 to 5 do 
    
    begin 
    
    if Player[i].goalScores > high then 
    
    begin 
    
    pName := Player[i].Name; 
    pTeam := Player[i].teamName; 
    high := Player[i].goalScores; 
    end; 
    end;
    
    for i := 1 to 5 do 
    
    begin 
    
    if Player[i].yellowCards < few then 
    begin 
    
    gYellow := Player[i].Name; 
    gTeam := Player[i].teamName; 
    few := Player[i].yellowCards; 
    end; 
    end; 
    end; 
    
    procedure display; 
    
    begin 
    
    writeln('Player Name Team Name Goal Score(s) Yellow Card(s)'); 
    writeln('-------------------------------------------------------------------'); 
    for i := 1 to 5 do 
    
    begin 
    
    writeln(Player[i].Name,' ', Player[i].teamName, ' ', Player[i].goalScores, ' ', Player[i].yellowCards); 
    end; 
    
    writeln; 
    writeln('Highest Scores Detail:'); 
    writeln('Name: ', pName); 
    writeln('Team Name: ', pTeam); 
    writeln; 
    
    writeln('Yellow Card Detail:'); 
    writeln('Name: ', gYellow); 
    writeln('Team Name: ', gTeam); 
    writeln; 
    
    writeln('Press <ENTER> to continue.'); 
    readln; 
    end; 
    
    begin 
    
    read; 
    display; 
    
    end.

    The only problem now is, how do I make them align? When I run it, it turns out like:

    gaga The Lions 9 9
    haha Gelang Rangers 1 0
    I want to make the numbers align.... Does anyone know how?

IMN logo majestic logo threadwatch logo seochat tools logo