Solved

About turbo pascal....starter.

Posted on 2000-03-17
2
269 Views
Last Modified: 2010-04-16
Please look at the following code

{-------------------------------------}
PROGRAM bank;

USES wincrt;

TYPE num= ARRAY[1..10] OF integer;
     money= ARRAY[1..10] OF real;
VAR
 data:text;
 numbers:num;
 search:boolean;
 i,wrong,right,n,id:integer;
 money1:money;

PROCEDURE loadata(VAR number:num; VAR moneys:money);
 VAR i:integer;
 BEGIN
  FOR i:=1 TO 10 DO
  readln(data,number[i],moneys[i]);
 END;

PROCEDURE dosearch(number2:num; VAR n2,numm:integer; VAR search2:boolean);
 VAR i:integer;

 BEGIN
  writeln('Please enter your ID numbers');
  read(numm);
  FOR i:=1 TO 10 DO
   IF numm=number2[i] THEN
    BEGIN
    search2:=true;
    n:=i
    END
 END;

PROCEDURE output(number3:num; moneys2:money; search3:boolean; VAR wrong2,right2:integer);
 BEGIN
  IF search3=true THEN
   BEGIN  
   writeln('Your ID numbers is ',number3[n]);
   writeln('You have $ ',moneys2[n]:1:2);
   right2:=right2+1;
   END
  ELSE
   BEGIN
   writeln('This ID is invalid');
   wrong2:=wrong2+1;
   END
 END;

BEGIN
 wrong:=0;
 right:=0;
 REPEAT;
 assign(data,'c:\tpw\account.inf');
 reset(data);
 loadata(numbers,money1);
 dosearch(numbers,n,id,search);
 output(numbers,money1,search,wrong,right);
 UNTIL id=9999;
  BEGIN
  writeln('Thanks for using me');
  writeln('You entered ',wrong,' invalid ID numbers and ',right,' valid ID numbers');
  writeln('Here is the information');
  writeln('ID#       BALANCE');    
   FOR i:=1 TO 10 DO
   writeln(numbers[i],'       ',money1[i]:1:2);
  END;
END.
{-------------------------------------------}
and here is the data
{------------------------------------------}
1357    33.50   Flo Chart
6666    150.33  Hedda Hare
3312    226.97  Holly Wud
1020    0.0     Sue Err
8282    78.77   Otto Mobile
2200    924.75  Howard Countee
1234    8000.00 Jim Sox
1313    1.00    Adam Upp
7971    0.0     Barney Ard
7894    445.12  Debihi
{------------------------------------------}
The program is work fine, but if enter a invalid number after a valid number then it will output the info for the last valid number
And it's always a one more value to what ever number you enter..doesn't matter it valid or invalid.

any question mail me at hua123@yahoo.com
0
Comment
Question by:debesta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 2630664
hi,
you should ask this in pascal programming section to get quicker response:

http://www.experts-exchange.com/Computers/Programming/Languages/Pascal/
0
 

Accepted Solution

by:
sunsetyang earned 50 total points
ID: 2633250
If not found,you forget to set the search value to false so it just use the last vaule.so ...
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression

707 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