Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |
 User Name: Password: Remember me

New Free Tools on Dev Shed!
We're Excited to announce that Dev Shed now has 70 free tools on the site. To learn more, click here!

 Add This Thread To: Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb
 « Previous Thread | Next Thread » Thread Tools Search this Thread Rate Thread Display Modes
 Dev Shed Forums Sponsor:
#1
February 3rd, 2006, 10:48 PM
 adungan
Registered User

Join Date: Feb 2006
Posts: 1
Time spent in forums: 1 h 17 m 8 sec
Reputation Power: 0
HELP!! Dev-Pascal First Program...

Hey guys,

I need major help. I am in an intro to computer programming class in school - but it feels more like ADVANCED programming to me. I can't get the instructor to return emails and I'm panicking.

Here is the program info...

I need to convert the equation '(b*b) - 4ac' into Pascal expressions. Then I need to write a program that will read in the values of a, b, and c and use these values to solve the expression. My output should be in tabular format and look something like this:

Mathematical Formula Pascal Expression Solution
-----------------------------------------------------------
b*b - 4ac b*b - 4ac 123.45

I know this is pretty basic, but I don't have a book for the class and all I have to go on are some notes from class.

Thanks for the help.

#2
February 4th, 2006, 12:12 AM
 Yegg`
Contributing User

Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,797
Time spent in forums: 3 Weeks 6 Days 21 h 54 m 27 sec
Reputation Power: 154
Comments on this post
CountVikernes agrees: Oops, it probably will better than my post. Just noticed. *laugh* Ah well. At least I did something
for awhile! *chuckle*

#3
February 4th, 2006, 07:00 AM
 CountVikernes
Contributing User

Join Date: Oct 2003
Location: Lisbon, Portugal
Posts: 154
Time spent in forums: 1 Day 14 h 37 m 54 sec
Reputation Power: 12
Heh, I just finished my first semestre where I had Pascal. I've pretty much forgotten the lot of it! *chuckle*

Going through a book helps. I had had a fair bit of programming experience beforehand, so I got through alright, but I noticed some of the guys who'd never programmed before got really stuck.

I can only give you a sort of introduction...

Guidelines:
- A function is not "allowed" to change any variables within itself.
- A function is not "allowed" to write or read anything from/to the console.
- A pr

ocecure
is allowed to change variables within itself, read and write from the console, but should not return any variable.

A program should look like this:

Code:
```program myProgramName;
var
... variable declaration ...

function myFunctionName1(myFunctionArguments): functionReturnType;
begin
... my function code ...
end;

procedure myProcedureName1(myProcedureArguments);
begin
... my procedure code ...
end;

begin
... my main program code ...
end.```

Right, I won't code for you, but I'll try to give you all you need to know. Let's break down what you need to do:

You have variables, so...
1) Let the computer know you need to have variables.

You need to read a, b and c from the console. Remember the guidelines up there?
2) Need a procedure to read stuff from the console, namely, a b c.

You need to use a formula... look at the guidelines again and ...
3) Need a function which processes a, b and c and returns the result of the formula.

Need to show the result to the user, so...
4) You either do that in the main program, or you can do an output procedure.

Four steps, that sounds about easy enough, right? So here's what you need to know codewise (you already sort of know the syntax).

Variables come in different types. Since you're only calculating, I'm guessing your variables are going to be things like 1, 2, 3, 4, 5, 6, 2386 and so forth. Those are integers, so you need to allocate memory space for three integer values - a, b, and c.

Up there in the var section, the syntax is:
Code:
```var
myvar1, myvar2, myvar3: varType1;
myvar2: varType2
myvar3: varType4```

Where myvar is the name you want to give your variables, and vartypes are the type of variable (strings, integers, reals, etc).

You know what each procedure and function is going to do, so you can write the main program with each step in turn, and then move on to write the actual functions and procedures.

Functions return values, so when you call a function, generally, you'll have something like:
Code:
`myVar := myFunction(myArgument1, myArgument2);`

Procedures don't need that, since they don't return values. However, they can change the arguments you've passed on to them.

When you define a function, all its arguments should be const, constants. That's because a function doesn't change any variables. A procedure might, so any variables you're planning on changing there should have var before them. I'll exemplify:

Code:
```procedure ChangeThisNumber(var myInt: Integer);
begin
myInt := 2006
end;

// Commented line: this is the main program now.
begin
x := 5;
ChangeThisNumber(x);
Writeln(x); // This will now print 2006
end.```

Pretty simple, huh? If you had written const instead of var, you'd get an error, because myInt was supposed to be constant and not variable.

When you pass several arguments, after "var myInt: Integer", you insert a semicolon and then another variable. Something along the lines of:

Code:
```procedure ChangeTheseVariables(var myInt: Integer; const myNumber: Integer; var myString: String);
begin
myInt := 2000 + myNumber;
myString := "The year is ";
end;

// Commented line: this is the main program now.
begin
x := 5;
s := "Lalalala";
ChangeTheseVariables(x, 6, s);
Writeln(s, x); // This will now print "The year is 2006", I *think*
end.```

Notice the constant doesn't get changed, but that all the variables that are assigned as "var" within the argument section can be changed with no problems.

Hopefully you know how to handle a procedure. There's input though. Well, that's simple. All you need is a Readln(myVar). Obviously, the user needs to know what the computer wants, so a "Write("Give me the number a: ");" and then a Readln(a); would probably work better.

Now, a could be a var within a procedure called "getMyInput"... so could b, and c. They could all be within a single procedure.

How about functions? Well, it's the same as procedures, but everything passed is a constant, and there's that thing near the end:
Code:
`function myFunction(myArguments): varType;`

See that varType? Remember when I told you functions returned some value? Well, the computer's got to know what type of variable everything is, so in your example, you're probably returning an integer. Just write integer there and you'll be OK.

Right. So, all you need now is a function with the expression, and you're off!

To tell the function to return a variable, you assign the function name, like so:
Code:
```function IncreaseString(const myString: String): String;
begin
IncreaseString := myString + " is happy.";
end;```

Notice how IncreaseString is the function name. That's why the function is returning a value. When you call the function, you'd get:

Code:
```s := "A pink elephant"
s2 := IncreaseString(s);
Writeln(s2); // This would now return "A pink elephant is happy."```

You didn't really change anything inside the function, you created something "new", which was assigned to s2.

Now, knowing that * is multiplication, / is division, and + and - are just what they are, you'll might be able to do that program.

Hmm, maybe you didn't even go as far as procedures. Ah well. You can tell I'm waiting for a download to finish, can't you? *chuckle*

Anyway, try it out yourself. I hope I helped some... if you show us some code that doesn't work, we'll be able to help you better by pointing out where the problem is at, and how to solve it.

It's better to understand it and do it yourself than to have the whole code written up for you.

Stop by again, hope you'll enjoy the course. It's a whole world out there. *grin*
__________________
"Get it hot! Hit it harder!!!"
--- The tutor warcry

ActivePython
Mark Pilgrim's Dive into Python E-book, thank this guy for his contribution to the Python community!

 Viewing: Dev Shed Forums > Other > Beginner Programming > HELP!! Dev-Pascal First Program...

## Developer Shed Advertisers and Affiliates

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap