New program - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

New program

vyirusvyirus Posts: 8Member
[color=Blue]hello there, am new at sortoff new into the pascal environment and would love to get some assistance in that please. i have to create a program that will allow the entry of 10 students

Comments

  • Pelle-48Pelle-48 Posts: 43Member
    You should use a pascal record structure like this:

    http://pascal-programming.info/lesson11.php
  • vyirusvyirus Posts: 8Member
    that is d code i started with so far but am getting alot of problems:

    program Grading_System;

    uses
    crt;

    var
    ClassNames : array[1..10] of string[20];
    ClassGen : array[1..10] of string[20];
    ClassAvg : array[1..10] of integer;
    LoopCounter : integer;
    NumberOfNames : integer;
    sum:integer;
    average: real;

    begin
    clrscr;
    write('How many names are you entering (max 10)? ');
    readln(NumberOfNames);

    {Input Names, Grades and Gender}
    LoopCounter := 1;
    while LoopCounter <= NumberOfNames do
    begin
    writeln;
    writeln('Enter Name: ',LoopCounter);
    readln(ClassNames[LoopCounter]);
    writeln;
    writeln('Enter Gender: ',LoopCounter);
    readln(ClassGen[LoopCounter]);
    writeln;
    writeln('Enter Average: ',LoopCounter);
    readln(ClassAvg[LoopCounter]);
    LoopCounter := LoopCounter + 1;
    end;

    {Print out names}
    writeln('Here is the list of names');
    LoopCounter := 1;
    while LoopCounter <= NumberOfNames do
    begin
    writeln(ClassNames[LoopCounter],' : ',ClassGen[LoopCounter],' : ',ClassAvg[LoopCounter]);
    LoopCounter := LoopCounter + 1;
    end;
    readln;

    {Students with 50+ average}
    writeln('Here is the percentage of students with 50+ average');
    LoopCounter := 1;
    while LoopCounter <= NumberOfNames do
    begin
    if ClassAvg[10] >= 50 then
    sum := 0;
    sum := sum + ClassAvg[10];
    average := sum / 100;
    writeln('Percentage of Students with 50+ average is: ',average:10:2,'%');
    LoopCounter := LoopCounter + 1;
    end;
    readln;

    end.
  • Actor21Actor21 Posts: 35Member
    [code]
    (*
    i have to create a program that will
    allow the entry of 10 students
  • vyirusvyirus Posts: 8Member
    thank you very much for your assistance, i just had to add in piece of the same code you had below to get for the males with 50+ average but it's working like a charm. I can't express my thanks but i really do appreciate you help much.
  • vyirusvyirus Posts: 8Member
    please help me with this. i have to find the gender with the highest number. both male and female that has the highest value, so i came up with this part of the code but am getting the same value for both male and female:

    {
    Female and Male with highest value
    }
    high := ClassAvg[1] ;
    low := ClassAvg[1] ;

    begin
    if (ClassAvg[LoopCounter] > high) and (ClassGen[LoopCounter] = 'M') then
    high := ClassAvg[LoopCounter] ;

    if (ClassAvg[LoopCounter] < low) and (ClassGen[LoopCounter] = 'M') then
    low := ClassAvg[LoopCounter] ;

    if (ClassAvg[LoopCounter] > high) and (ClassGen[LoopCounter] = 'F') then
    high := ClassAvg[LoopCounter] ;

    if (ClassAvg[LoopCounter] < low) and (ClassGen[LoopCounter] = 'F') then
    low := ClassAvg[LoopCounter] ;
    end;
    writeln('Male with highest grade is: ',ClassNames[LoopCounter],' - ',ClassGen[LoopCounter],' : ',high) ;
    readln ;
    writeln('Female with highest grade is: ',ClassNames[LoopCounter],' - ',ClassGen[LoopCounter],' : ',high) ;
    readln
  • Actor21Actor21 Posts: 35Member
    This is a fragment. I have not had time to compile and test it.

    [code]
    var
    .
    .
    .
    Marker : char ;
    Index : integer ;
    GenStr : string[6] ;

    begin
    .
    .
    .
    {
    Female and Male with highest value
    }
    Marker := 'F' ;
    while Marker <= 'M' do begin
    if Marker = 'F' then
    GenStr := 'Female'
    else
    GenStr := 'Male' ;

    Index := 0 ;
    Max := 0 ;
    for LoopCounter := 1 to NumberOfNames do begin
    if (ClassGen[LoopCounter] = Marker) and (ClassAvg[LoopCounter] > Max) then begin
    Max := ClassAvg[LoopCounter] ;
    Index := LoopCounter
    end
    end ;

    if Index = 0 then
    writeln ('There are no ', GenStr, 's in the class.')
    else
    writeln (ClassNames[Index], ' with an average of ',
    ClassAvg[Index], ' is the highest ranking',
    Genstr, ' in the class.') ;

    Marker := 'M'
    end ;
    [/code]
  • vyirusvyirus Posts: 8Member
    thank you very much but i have to get both gender; male and female with the highest grade of the program. i have used what you have created and am trying to adjust it but am getting an infinity loop. just keep going, please assist me in that but am also trying to curb the problem.
  • Actor21Actor21 Posts: 35Member
    Sorry about that. As I said I didn't have time to test it. This should cure the infinite loop. The code handles Female the first time through the loop and Male the second time.
    [code]
    var
    .
    .
    .
    Marker : char ;
    Index : integer ;
    GenStr : string[6] ;
    Count : 1 .. 2 ;

    begin
    .
    .
    .
    {
    Female and Male with highest value
    }
    [red]for Count := 1 to 2 do begin { loop two times }
    if Count = 1 then begin { 'Female' the first time thru }
    Marker := 'F' ;
    GenStr := 'Female'
    end
    else begin { 'Male' the second time thru }
    Marker := 'M' ;
    GenStr := 'Male'
    end ;
    [/red]

    Index := 0 ;
    Max := 0 ;
    for LoopCounter := 1 to NumberOfNames do begin
    if (ClassGen[LoopCounter] = Marker) and (ClassAvg[LoopCounter] > Max) then begin
    Max := ClassAvg[LoopCounter] ;
    Index := LoopCounter
    end
    end ;

    if Index = 0 then
    writeln ('There are no ', GenStr, 's in the class.')
    else
    writeln (ClassNames[Index], ' with an average of ',
    ClassAvg[Index], ' is the highest ranking',
    Genstr, ' in the class.')
    end ;
    [/code]
  • Actor21Actor21 Posts: 35Member
    : [color=Blue]hello there, am new at sortoff new into the pascal
    : environment and would love to get some assistance in that please. i
    : have to create a program that will allow the entry of 10 students
  • vyirusvyirus Posts: 8Member
    hey, no i don't no much of them things especially in the Pascal environment. I was just given a crash course in it online and by some friends in order to get myself in it. so can you please give me some assistance in it since am beginning to love the programming sector and am thinking of getting into it full time because i love creating solutions. Thanks again Actor21, u have been a great help and i do appreciate all you have done for me.
Sign In or Register to comment.