Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Other Programming Languages (http://www.programmingforums.org/forum38.html)
-   -   Little bit of pascal help (http://www.programmingforums.org/showthread.php?t=11265)

irish Sep 7th, 2006 1:26 PM

Little bit of pascal help
 
Ok so I found out I might be learning pascal for AS Computing. So I started looking at it late last night and ive found it easy enough so far. I have one problem though, I can't work out how to reuse a previous set of code for a later section of the program.

:

1:        program        XIF
2:
3:        var        value:        integer;
4:
5:        begin
6:                Writeln('Please enter a value for x:');
7:                Readln(value);
8:                if value > 5 then
9:                        Writeln('Input accepted');
10:                else
11:                        Writeln('Invalid input, try again:');
12:                At this point it would return to line 7
13:                (to read the input as the value var).
14:        End.


I did google the problem and looked at some tutorial sites, but things like these wouldnt work:

:

CONDITION:
Readln(value);
        if value > 5 then
                Writeln('Input accepted');
        else
                Writeln('Invalid input, try again:');


:

GOTO 7;

Btw I am using Turbo Pascal (just for the info).

hoffmandirt Sep 7th, 2006 1:39 PM

Did you look up how to write procedures using pascal? I'm not sure if those are what you want, but when I think of reusable code, the first thing that comes to my mind is functions/procedures/sub routines, whatever you want to call them.

_James_ Sep 7th, 2006 2:27 PM

A Level Computing is not just about programming. If you are good at programming or have a natural ability you will find the AS course boring and simple. A2 is more demanding but still is not too hard for someone with some intelligence. Most people will start it thinking its all programming and probably wont have much experience in programming either. Take a shot gun into theroy lessons to shoot the person who has a huge ego and always answers questions incorrectly(there is always one, two years with this idoit who would never shut up really put me off theory lessons).

Firstly find out what language is taught. It might be pascal, but it could be VB6/.net. Secondly get a book on the language you will be taught. Read it through and then you will find that what you want to do is very easy to accomplish. Thirdly let your teacher teach you the basics. You might not even need a book if the standard of notes and teaching is good. If you have a good teacher you will understand more easily and you can ask questions just like this to them. Good luck

irish Sep 7th, 2006 3:11 PM

Quote:

A Level Computing is not just about programming.
I didnt try to say that i thought it was only about programming, i was simply saying that it was between pascal and vb, but my teacher said it was 90% going to be pascal so i started looking at that, im only wanting to be given a slight hint about what way i would/could go about finishing this small prog.

Quote:

Take a shot gun into theroy lessons to shoot the person who has a huge ego and always answers questions incorrectly
I dont know if you mean someone in my class or you are suggesting that I have a huge ego.
If you mean someone in my class: lol
If you mean me: I do not have a huge ego, you might have interpreted what I typed completely wrong.

And I do enjoy theory alot anyway, theres no one in my class that always answers questions wrong (ppl normally go quiet and wait for the teacher to give them the answer if they arent sure what it is lol).

Thanks for the advice anyway :)

_James_ Sep 7th, 2006 3:29 PM

No you have got me all wrong. I was just telling you what A-Level computing is like. I did it a few years ago. You will find that 2/3 of all lessons will be theory. Its very boring at times. Just learn the material and you will be fine. The exams in the first year are largely based on theory and one is parly based on a project.

I was not saying you have a huge ego. I think what you are doing is a good idea. Learning in your own time shows you have a healthy interest in programming and it will come in handy. By asking for help in this forum you have shown that you have no huge ego. :)

I had a kid in my class for two years who was so anoying. When the teacher would ask a question he would just burt out some random rubbish that was normally very inaccurate without being asked. He would even randomly add to what the teacher was saying without any question being put forward. He was a poor programmer. He was always getting pissed off with me as I would complete the task set quickly and correctly in practical sessions. He would then try to show that my code was wrong just to make himself look good and he never succeded at that. In the end I told him to shut the fuck up. I did it out loud in class when the teacher was going over something I found interesting and wanted to understand. He kept interrupting and it was anoying everyone. The funny thing was he then stod up and left the room and I was told by the teacher that he had wanted to say that all year but could not swear at a student. I was in a bad mood that day, I was wrong to say it out loud.

Anyway. If you know the answer then answer when asked. Dont be a smart ass or you will make everyone else look at you when the teacher asks a question. I had this very issue in Chemistry. Its not good, as in the end even the teacher will ask you for an answer even if you have not put your hand up.

Ooble Sep 7th, 2006 7:05 PM

Check out procedures and functions. They're not easy, so I'm not going to go into depth - that's what books and teachers are for - but they're basically ways of modularising code so you can re-use it. Look 'em up.

irish Sep 8th, 2006 6:13 AM

Thanks lads, bored in a 'study period' (nothing to study this time of year) at the minute so i might as well look em up now :).

Thanks again :)

irish Oct 10th, 2006 8:58 PM

A hell of alot easier than I first thought it would be, i just needed to use:

:

repeat
        <statements>
until <condition>


Thanks for the advice ^^

DaWei Oct 10th, 2006 9:34 PM

You still need to look up procedures. They can be invoked from any point, whereas your example only reuses the code at that one particular place.
http://www.daweidesigns.com/images/procedure.gif

irish Oct 11th, 2006 9:53 AM

Thanks for the advice DaWei ^^


All times are GMT -5. The time now is 1:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC