Can anyone help with simple code polease? 
Author Message
 Can anyone help with simple code polease?

I'm doing an A-level course in computing (2nd year) and we are learning
Pascal. Our assignment was to make a program that lets a user input 2
numbers, and then it hsould add them together. then if we go tthat working,
we had to subtract hrem and multiplay for extra marks.

I got that fine. Easy as pi (being 3.14159265358979323846264...) but what I
would like is when the user inputs a letter or symbol instead of a number,
for an error to appear, saying "sorry, u r an idiot" (or somehting to tat
effect). right now, when I press a leter, it just quits and goes back to the
compiler, saying samething like invalid numeric format.

here is the code I have so far:

program testprogram;

uses Crt;

var
   a,b,sum,sub1,sub2,mul      :integer;
   wholenum                   :integer;        <<<note I want htins
changing>>>

   begin
   clrscr;

        write('Enter the first Integer: ');
        readln(a);

  if a <> wholenum then            <<<see below>>>
   begin
    writeln('That is not a valid number. Please type an INTEGER.');
    readln(a);
   end

   else
   begin
    write('Enter the second Integer: ');
    readln(b);
   end;

  if b <> wholenum then
   begin
    writeln('That is not a valid number. Please type an INTEGER.');
    readln(b);
   end

          else
   begin
    write('Enter the second Integer: ');
    readln(b);
   end;

   sum:=a+b;
   sub1:=a-b;
   sub2:=b-a;
   mul:=a*b;

             writeln('');
             writeln('The sum of the two numbers is: ',sum);
             writeln('The difference between the first and second number is:
',sub1);
             writeln('The difference between the second and first number is:
',sub2);
             writeln('When you multiply the two numbers together, the
product is: ',mul);
   readln;

   clrscr;

end.

what I want is for wholenum to be declared as an integer, but it can be any
value. that way, I can put:

if a /=/ wholenum then write 'idiot'

see what I am tlakign about?

pelase help!

thanx

matt

--
"Easy is it not, to talk forward, when hand up your ass there is."
Yoda



Mon, 03 Mar 2003 03:00:00 GMT  
 Can anyone help with simple code polease?

Quote:
>I'm doing an A-level course in computing (2nd year) and we are learning
>pascal. Our assignment was to make a program that lets a user input 2
>numbers, and then it hsould add them together. then if we go tthat working,
>we had to subtract hrem and multiplay for extra marks.

>I got that fine. Easy as pi (being 3.14159265358979323846264...) but what I
>would like is when the user inputs a letter or symbol instead of a number,
>for an error to appear, saying "sorry, u r an idiot" (or somehting to tat
>effect). right now, when I press a leter, it just quits and goes back to the
>compiler, saying samething like invalid numeric format.

Read the input as a string in a repeat loop then use the Val procedure -
look it up in your help file - to convert it to a number. If there is an
error code returned you can test for it.

--
Pedt



Tue, 04 Mar 2003 11:24:03 GMT  
 Can anyone help with simple code polease?
ahh (went right over m y head)

I **think** ur saying this:

use val (validate?) to validate it as a number in the loop (instead of the
if/then/else) and that should do it?

right?

(*I think I can do this)

--
"Easy is it not, to talk forward, when hand up your ass there is."
Yoda


Quote:

> >I'm doing an A-level course in computing (2nd year) and we are learning
> >pascal. Our assignment was to make a program that lets a user input 2
> >numbers, and then it hsould add them together. then if we go tthat
working,
> >we had to subtract hrem and multiplay for extra marks.

> >I got that fine. Easy as pi (being 3.14159265358979323846264...) but what
I
> >would like is when the user inputs a letter or symbol instead of a
number,
> >for an error to appear, saying "sorry, u r an idiot" (or somehting to tat
> >effect). right now, when I press a leter, it just quits and goes back to
the
> >compiler, saying samething like invalid numeric format.

> Read the input as a string in a repeat loop then use the Val procedure -
> look it up in your help file - to convert it to a number. If there is an
> error code returned you can test for it.

> --
> Pedt



Tue, 04 Mar 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Need Help With Simple CODE

2. It's not bad canned meat...

3. Simple Sauce (haha) code required.

4. Need simple source code

5. assistance on code((Very simple encription)

6. assistance on code (VERY simple encription)

7. Simple code generation question

8. source code for a simple database program...

9. What's wrong with this simple code????

10. simple sound card code

11. I want some simples source codes for pascal

12. Anyone know of good freeware code for Ascii Text Import

 

 
Powered by phpBB® Forum Software