Languages :: Pascal :: Help with a Pascal Program |
|||
| By: ben22 |
Date: 15/06/2003 00:00:00 |
Points: 125 | Status: Answered Quality : Excellent |
|
Hello, I am new to programming, and I was just assigned a project in class that I am having trouble completing. I need to write a program that allows the user to enter a number between 1 and 999 and gives that number back to them written out. For example, if 456 were typed in, the output should be FOUR HUNDRED FIFTY-SIX. I already know that I'm going to use the div and mod functions to get the hundreds, tens, and ones digits, but now we have to use procedures and parameters, and I have never used them before. I have to use a total of six procedures, to 1.display a welcome message 2. print the word corresponding to an integer from 1 to 9 (i.e., "one", "two", etc.) 3. print the word corresponding to the tens version of integers between 2 and 9 (i.e., "twenty", "thirty", etc.) 4.print the word corresponding to the teens version of integers between 0 and 9 (i.e., "ten", "eleven", "twelve", etc.) 5. calculate the hundreds digit of a number between 0 and 999 have one value parameter (the number), and one variable parameter (that holds the result) 6. calculate the tens digit of a number between 0 and 99 have one value parameter (the number), and one variable parameter (that holds the result) . what i have so far. {<Ben Bucher> <CS 7 Intro to Programming> <bcb23@pitt.edu>} {The purpose of this program is to take user input in the form of a number from 1-999 and write it out as a person would say it.} program breakup; const width = 1; var hunds, tens, ones : integer; procedure Welcome; begin writeln('Welcome to the Number Master! by Ben Bucher'); writeln('If you type in a number, I will write it out for you.') end; begin Welcome; end; procedure Getnum(amtleft : integer); var amt: integer; begin if (amt > 0) and (amt < 1000) then hunds:= amt div 100 amtleft:= amtleft mod 100 end; begin writeln('Please enter a number between 1 and 999'); readln(amt); Getnum(hunds); end. Please explain how to set up my procedures and how to get my parameters. Any/all help would be greatly appreciate. -Ben ^G Get Help ^O WriteOut ^R Read File ^Y Prev Pg ^K Cut Text ^C Cur Pos ^X Exit ^J Justify ^W Where is ^V Next Pg ^U UnCut Text^T To Spell |
|||
| By: Okey | Date: 15/06/2003 08:36:00 | Type : Comment |
|
| tip listen to your teacher next year when repeating! |
|||
| By: VGR | Date: 15/06/2003 15:12:00 | Type : Answer |
|
| @ okékette tip : if that's all you have to say, just shut up @ Ben : at least you seem to have understood the principles of parameter passing and routine building : var hunds, tens, ones : integer; // global variables procedure Getnum(amtleft : integer); // formal parameter name begin // use amtleft argument end; // GetNum begin // main Getnum(hunds); // parameter-argument passing end. I think you thus shouldn't have any problem doing your job. Here are some tips : 2. think : which is the Pascal control structure that enables an elegant and efficient choice between ten ordinal values ? Tip : it's called switch() in C and PHP 3. strictly similar 4. should I repeat ? 5. you have the tools you need : DIV and MOD and the parameters were even specified for you ! have one value parameter (the number), and one variable parameter (that holds the result) A function has this structure : Function thefunc(thepar : thetype) : therturnedtype; Var theretvalue : thereturnedtype; Begin // analyse thepar, make computations, build theretvalue // effectively return value thefunc:=theretvalue; End; { thefunc thereturnedtype Function } 6. shouldn't be too much a problem after (5) regards |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








