Solved

output doesn't match number

Posted on 2000-04-17
1
173 Views
Last Modified: 2010-04-16
Here's my program:

var i: integer;

type string10 = string[10];


const
  ones: array[0..9] of string10 = ('', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
  tens: array[0..9] of string10 = ('','ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety');


function wordnumber (number: word) : string;
  begin
     wordnumber:= tens [number div 10] + '-' +ones [number div 10];
  end;

begin {main}
   for i:= 20 to 99 do
     writeln ('You write ',i, ' like this: ', wordnumber(i));
end.



This is the output it's giving me:

'You write 20 like this: twenty-two'

It gives me twenty-two from 20 to 29.

I'm having similar problems with the other numbers:

'You write 30 like this: thirty-three'   I get thirty-three from 30 to 39.

'You write 40 like this: forty-four'    I get forty-four from 40 to 49.

'You write 50 like this: fifty-five'  I get fifty-five from 50 to 59.

'You write 60 like this: sixty-six'  I get sixty-six from 60 to 69.

'You write 70 like this: seventy-seven'   I get seventy-seven from 70 to 79.

'You write 80 like this: eighty-eight'    I get eighty-eight from 80 to 89.

'You write 90 like this: ninety-nine'   I get ninety-nine from 90 to 99.


BTW... The program is supposed to let the user enter a number from 20 rto 99 and it outputs the number in equivalent number form.
0
Comment
Question by:kazooie21
1 Comment
 
LVL 12

Accepted Solution

by:
Hypo earned 10 total points
ID: 2724272
Hi,
There's one misstake in your code,
One of the "div"s should be a "mod"

Here's a modifyed version of your code

var i: integer;

type string10 = string[10];

const
  ones: array[0..9] of string10 = ('', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
  tens: array[0..9] of string10 = ('','ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety');


function wordnumber (number: word) : string;
  begin
     wordnumber:= tens [number div 10] + '-' +ones [number mod 10];
  end;

begin {main}
   for i:= 20 to 99 do
     writeln ('You write ',i, ' like this: ', wordnumber(i));
end.


0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi: Read a array of strings in a OleVariant 4 1,136
HTTP-POST Delphi 7 5 2,894
How to open a file in read-write mode, and lock out others 2 270
Regular Expression to Split a String 7 110
One of the biggest threats facing all high-value targets are APT's.  These threats include sophisticated tactics that "often starts with mapping human organization and collecting intelligence on employees, who are nowadays a weaker link than network…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now