Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
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.

Help me quick please!

ph_decontrolph_decontrol Posts: 1Member
PROGRAM higher;

USES CRT;

CONST
max=100;

VAR
supplier:ARRAY[1..max] OF STRING;
loop, total, counter, namelength, enter:INTEGER;
choice:STRING[20];
flag:BOOLEAN;

PROCEDURE headings;
BEGIN
CLRSCR;
TEXTMODE(C80);
GOTOXY(1,2);
TEXTCOLOR(1);
WRITELN('Higher');
WRITELN('~~~~~~');
TEXTCOLOR(2);
GOTOXY(1,4);
WRITELN('1. Main Program');
TEXTCOLOR(3);
GOTOXY(1,5);
WRITELN('2. Help');
TEXTCOLOR(4);
GOTOXY(1,6);
WRITELN('3. Exit');
GOTOXY(1,8);
WRITELN('Enter Choice');
READLN(enter);
END;

PROCEDURE get_details;
BEGIN
CASE ENTER OF
1:
BEGIN
loop:=0;
REPEAT
loop:=loop+1;
TEXTMODE(C80);
TEXTCOLOR(1);
GOTOXY(1,2);
WRITELN('Main Program:Step 1');
WRITELN('~~~~~~~~~~~~~~~~~~~');
TEXTCOLOR(4);
GOTOXY(1,4);
WRITELN('Enter XXX At Any Time To End Program');
TEXTCOLOR(14);
GOTOXY(1,6);
WRITELN('Enter Supplier Name ',loop,':');
TEXTCOLOR(11);
READLN(supplier[loop]);
UNTIL supplier[loop]='XXX';
READLN;
END;
END;
CASE ENTER OF
2:
BEGIN
CLRSCR;
WRITELN('Welcome To Help');
READLN;
END;
3:
BEGIN
CLRSCR;
WRITELN('Program Ending...');
END;
ELSE
WRITELN('The Number, ',enter,', is an invalid number');
READLN;
END;
END;

PROCEDURE display;
BEGIN
CLRSCR;
FOR counter:=1 TO loop-1 DO
BEGIN
TEXTCOLOR(1);
GOTOXY(45,4);
WRITELN('Original Supplier List:');
GOTOXY(45,counter+5);
TEXTCOLOR(11);
WRITELN(supplier[counter]);
END;
END;

PROCEDURE validation;
BEGIN
REPEAT
flag:=true;
TEXTCOLOR(1);
GOTOXY(1,2);
WRITELN('Main Program:Step 2');
WRITELN('~~~~~~~~~~~~~~~~~~~');
TEXTCOLOR(14);
GOTOXY(1,4);
WRITELN('Enter Supplier Name To Be Found');
TEXTCOLOR(11);
READLN(choice);
namelength:=length(choice);
FOR counter:=1 TO namelength DO
BEGIN
IF
choice[counter] IN ['A'..'Z','a'..'z','0'..'9',' ']
THEN
WRITELN('Supplier Name Is Valid')
ELSE
BEGIN
WRITELN('Supplier Name Is Invalid');
flag:=false;
END;
END;
UNTIL flag=true;
END;

PROCEDURE occur;
BEGIN
total:=0;
FOR counter:=1 to loop DO
BEGIN
IF
supplier[counter]=choice
THEN
total:=total+1;
END;
END;

PROCEDURE nothin;
BEGIN
TEXTCOLOR(4);
GOTOXY(1,8);
WRITELN('The Supplier ',choice,' appears ',total,' time(s)');
END;

BEGIN
CLRSCR;
REPEAT
headings;
get_details;
display;
validation;
occur;
nothin;
UNTIL ENTER=3;
WRITELN('Program ending...press ');
READLN;
END.

Ok, so this program was first designed to ask the use to enter the name(s) of suppliers and if 'XXX' was entered then the program should stop asking the user for any supplier names and on a new page display the supplier list created, then ask the user for a supplier name so it can be checked against the list, and if it is there a message should be dispalyed saying how many times it occurs in the list. It should also check that the charcacters enetered(only for the occurrenes check, not the original supplier list)should be letters, numbers or spaces. If they are a message hsould be displayed confirming that all charcters are valid and if not a message should dipslay saying they are not valid. After I had all this working, i decided to create a main menu screen, which would allow you to go to the main program(after this had been run the program should end, not go back to main menu), a help option(if this was selected and viewed it should go back to the main menu NOT the main program) and to exit. I can't change the coding so that when i select the number for the option i want it goes to the correct option and does the required things. Does anyone know how i could alter the program coding so that it does everythin i have stated correctly?

This is not homework.

Comments

  • charlekcharlek Posts: 2Member
    Hello
    My name is charles Katuri and i live in Zimbabwe. I am a student at gokomere high school doing my A-levels. I am using pascal 6 in my project ofr computer science. I would suggest. You make a function that
    will print out the menu options and associated keys and returns the value of the integer chosen.
    use a cace statement to see which option has been chosen.
    you put this in a repeat loop and you are fine. I suggest you make most of the things into procedures
    eg
    function getopt : integer;
    begin
    writeln('choose option by pressing number');
    writeln('dddddddddddddd'
    writeln( '1 : enter name' )
    end;

    this is the main program as i would sugeest it
    begin
    repeat
    begin
    case getopt of
    1:begin ...end;
    2: begin end;
    .
    .
    .
    8 : begin
    stop := true
    end;
    end
    until stop = true;

    it allows fr program to branch to any procedure and always return to menu. sorry i could not give a better explanation because
    i am running out of time to surf.
    i hope i ahve shed some light.

    charlek
    : PROGRAM higher;
    :
    : USES CRT;
    :
    : CONST
    : max=100;
    :
    : VAR
    : supplier:ARRAY[1..max] OF STRING;
    : loop, total, counter, namelength, enter:INTEGER;
    : choice:STRING[20];
    : flag:BOOLEAN;
    :
    : PROCEDURE headings;
    : BEGIN
    : CLRSCR;
    : TEXTMODE(C80);
    : GOTOXY(1,2);
    : TEXTCOLOR(1);
    : WRITELN('Higher');
    : WRITELN('~~~~~~');
    : TEXTCOLOR(2);
    : GOTOXY(1,4);
    : WRITELN('1. Main Program');
    : TEXTCOLOR(3);
    : GOTOXY(1,5);
    : WRITELN('2. Help');
    : TEXTCOLOR(4);
    : GOTOXY(1,6);
    : WRITELN('3. Exit');
    : GOTOXY(1,8);
    : WRITELN('Enter Choice');
    : READLN(enter);
    : END;
    :
    : PROCEDURE get_details;
    : BEGIN
    : CASE ENTER OF
    : 1:
    : BEGIN
    : loop:=0;
    : REPEAT
    : loop:=loop+1;
    : TEXTMODE(C80);
    : TEXTCOLOR(1);
    : GOTOXY(1,2);
    : WRITELN('Main Program:Step 1');
    : WRITELN('~~~~~~~~~~~~~~~~~~~');
    : TEXTCOLOR(4);
    : GOTOXY(1,4);
    : WRITELN('Enter XXX At Any Time To End Program');
    : TEXTCOLOR(14);
    : GOTOXY(1,6);
    : WRITELN('Enter Supplier Name ',loop,':');
    : TEXTCOLOR(11);
    : READLN(supplier[loop]);
    : UNTIL supplier[loop]='XXX';
    : READLN;
    : END;
    : END;
    : CASE ENTER OF
    : 2:
    : BEGIN
    : CLRSCR;
    : WRITELN('Welcome To Help');
    : READLN;
    : END;
    : 3:
    : BEGIN
    : CLRSCR;
    : WRITELN('Program Ending...');
    : END;
    : ELSE
    : WRITELN('The Number, ',enter,', is an invalid number');
    : READLN;
    : END;
    : END;
    :
    : PROCEDURE display;
    : BEGIN
    : CLRSCR;
    : FOR counter:=1 TO loop-1 DO
    : BEGIN
    : TEXTCOLOR(1);
    : GOTOXY(45,4);
    : WRITELN('Original Supplier List:');
    : GOTOXY(45,counter+5);
    : TEXTCOLOR(11);
    : WRITELN(supplier[counter]);
    : END;
    : END;
    :
    : PROCEDURE validation;
    : BEGIN
    : REPEAT
    : flag:=true;
    : TEXTCOLOR(1);
    : GOTOXY(1,2);
    : WRITELN('Main Program:Step 2');
    : WRITELN('~~~~~~~~~~~~~~~~~~~');
    : TEXTCOLOR(14);
    : GOTOXY(1,4);
    : WRITELN('Enter Supplier Name To Be Found');
    : TEXTCOLOR(11);
    : READLN(choice);
    : namelength:=length(choice);
    : FOR counter:=1 TO namelength DO
    : BEGIN
    : IF
    : choice[counter] IN ['A'..'Z','a'..'z','0'..'9',' ']
    : THEN
    : WRITELN('Supplier Name Is Valid')
    : ELSE
    : BEGIN
    : WRITELN('Supplier Name Is Invalid');
    : flag:=false;
    : END;
    : END;
    : UNTIL flag=true;
    : END;
    :
    : PROCEDURE occur;
    : BEGIN
    : total:=0;
    : FOR counter:=1 to loop DO
    : BEGIN
    : IF
    : supplier[counter]=choice
    : THEN
    : total:=total+1;
    : END;
    : END;
    :
    : PROCEDURE nothin;
    : BEGIN
    : TEXTCOLOR(4);
    : GOTOXY(1,8);
    : WRITELN('The Supplier ',choice,' appears ',total,' time(s)');
    : END;
    :
    : BEGIN
    : CLRSCR;
    : REPEAT
    : headings;
    : get_details;
    : display;
    : validation;
    : occur;
    : nothin;
    : UNTIL ENTER=3;
    : WRITELN('Program ending...press ');
    : READLN;
    : END.
    :
    : Ok, so this program was first designed to ask the use to enter the name(s) of suppliers and if 'XXX' was entered then the program should stop asking the user for any supplier names and on a new page display the supplier list created, then ask the user for a supplier name so it can be checked against the list, and if it is there a message should be dispalyed saying how many times it occurs in the list. It should also check that the charcacters enetered(only for the occurrenes check, not the original supplier list)should be letters, numbers or spaces. If they are a message hsould be displayed confirming that all charcters are valid and if not a message should dipslay saying they are not valid. After I had all this working, i decided to create a main menu screen, which would allow you to go to the main program(after this had been run the program should end, not go back to main menu), a help option(if this was selected and viewed it should go back to the main menu NOT the main program) and to exit. I can't change the coding so that when i select the number for the option i want it goes to the correct option and does the required things. Does anyone know how i could alter the program coding so that it does everythin i have stated correctly?
    :
    : This is not homework.
    :



Sign In or Register to comment.