User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 426,937 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,420 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 6342 | Replies: 62
Reply
Join Date: Nov 2007
Posts: 44
Reputation: Gotovina7 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Gotovina7 Gotovina7 is offline Offline
Light Poster

Re: Pascal calculator program

  #21  
Nov 19th, 2007
So I started all over since I can't use records. What I wrote here wont compile.

                          
program Assignment6(input, output);

Var
   input            : text;
   temporary_result : real;
   equation         : string[255];
   myArrayEquation  : array[1..100] of string[255];
   first_digit      : char;
   num              : integer;

BEGIN
   assign(input, 'input.txt');
   reset(input);
   read(input, equation);




end.


procedure ignore_space;

begin

   while first_char := ' ' do
      read(input, first_digit);

end;

procedure find_number;

begin

   num := 0;
   while (ord(first_digit) >= ord('0')) and (ord(first_digit) <= ord('9')) do
   begin
      num := num * 10 + (ord(first_digit) - ord('0'));
      read(input, first_digit);
   end;
end;

I get these errors
c6.p:23: warning: missing program header
c6.p:23: only one program declaration allowed
c6.p:23: syntax error before `Procedure'

Not sure where I should go from here.
Last edited by Gotovina7 : Nov 19th, 2007 at 8:35 pm.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Pascal calculator program

  #22  
Nov 20th, 2007
You are thinking in C. Don't put anything after the end. (that's "end" with a period after it). A program looks just like a giant procedure, with subroutines (procedures and functions) in it.

Did your professor tell you how he expects you to store your equation in an array? Or give any direction on how to solve it?
Reply With Quote  
Join Date: Nov 2007
Posts: 44
Reputation: Gotovina7 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Gotovina7 Gotovina7 is offline Offline
Light Poster

Re: Pascal calculator program

  #23  
Nov 20th, 2007
Originally Posted by Duoas View Post
You are thinking in C. Don't put anything after the end. (that's "end" with a period after it). A program looks just like a giant procedure, with subroutines (procedures and functions) in it.

Did your professor tell you how he expects you to store your equation in an array? Or give any direction on how to solve it?


Ooh I see now.

But yea, my prof didn't really say anything about how we store the equation in the array
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Pascal calculator program

  #24  
Nov 20th, 2007
I think you ought to go sit down with your professor and ask for some more details about how he wants you to solve the problem. If you ask correctly (professors, as all people, generally love to talk about their subject) you might get a lot more information than otherwise, which will help you figure things out. Don't let him push you out. It is his job to help you understand, so if you are still confused about something in particular, just say: "I don't understand why ..." or "If I understand right, I need to ...".

Good luck.
Reply With Quote  
Join Date: Nov 2007
Posts: 44
Reputation: Gotovina7 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Gotovina7 Gotovina7 is offline Offline
Light Poster

Re: Pascal calculator program

  #25  
Nov 21st, 2007
So basically I need to put the equations into an array, have a procedure that ignore spaces. Another procedure that will evaluate brackets first and so on.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Pascal calculator program

  #26  
Nov 21st, 2007
"Yes."
Reply With Quote  
Join Date: Nov 2007
Posts: 44
Reputation: Gotovina7 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Gotovina7 Gotovina7 is offline Offline
Light Poster

Re: Pascal calculator program

  #27  
Nov 24th, 2007
Man I am just soo lost for this assignment. I keep trying different things but nothing works.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Pascal calculator program

  #28  
Nov 24th, 2007
That's because you keep thinking the computer can help you. Computers never help anyone. They're too stupid.

Turn the computer off. Get out some colored paper and some crayons and draw how you (that is, how you, personally) can solve equations like:

1+2+3
-9+10
5*(2+3)
(2*(1+3))-1

(These are ordered by increasing difficulty.) Be sure to nitpick. "First, my eyeball saw '1'. That's a number. Then my eyeball saw a '+'. That's good, because a number needs to be followed by an operator." Etc.

Once you can tell yourself how to solve the problem, then it is time to start thinking in terms of how to make the computer do it. Each step you made might be one or two or three steps the computer will make. Each one of those steps might be made up of even smaller steps.

For example, a big step might be "find the outermost matching parentheses." A smaller step would be something like "find the first '('", and "find the matching ')' [skipping intervening '(' and ')']".

Start thinking your way through this, then when you think you can explain how to do each collection of steps (both big steps and small steps), then post back and I'll help you more.
Last edited by Duoas : Nov 24th, 2007 at 7:52 pm.
Reply With Quote  
Join Date: Nov 2007
Posts: 44
Reputation: Gotovina7 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Gotovina7 Gotovina7 is offline Offline
Light Poster

Re: Pascal calculator program

  #29  
Nov 24th, 2007
Man I am just soo lost for this assignment. I keep trying different things but nothing works. This is what I got i guess.

program Assignment6(input, output);
Var
   file1 : text;
   c     : char;
   error : boolean;
   num1  :  integer;

function convert(c: char): integer;
begin
   convert := ord(c) - ord('0');
end; { convert }

procedure  find_digits(num : integer);

   num := 0;
   while (ord(c) >= ord('0')) and (ord(c) <= ord('9')) do
begin
   num := num * 10 + (ord(c) - ord('0'));
   read(file1, c);
end;
end; { find_digits }

procedure ignorespaces;
begin
   while c = ' ' do
      read(file1, c);
end; { ignore_spaces }



BEGIN

   assign(file1, 'input.txt');
   reset(file1);
   read(file1, c);
   error := false;
   ignorespaces;
   If ((ord(c) >= ord('0')) and (ord(c) <= ord('9'))) then
begin
   find_digits;
   num1 := num;

end;


end.



The problem is the "num1 := num;" part. I can't seem to get this to work. I get undeclared identifier.
Last edited by Gotovina7 : Nov 24th, 2007 at 7:58 pm.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Pascal calculator program

  #30  
Nov 24th, 2007
Your find_digits is good, but it never lets go of "num".

find_digits;
{ What is num? }

I would make it a function:
function find_digits( var c: char ): integer;

Then you can learn num:
the_number := find_digits( c );

You also need that var c because c is always the next character read from the file. If you don't have that, then the last character read from file by find_digits will be lost. Make sense?

Hope this helps.
Last edited by Duoas : Nov 24th, 2007 at 7:58 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 12:20 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC