Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Need Help In Few Questions [Pascal]

pascal

  • Please log in to reply
7 replies to this topic

#1 JP16.1470

JP16.1470

    CC Lurker

  • Just Joined
  • Pip
  • 8 posts

Posted 11 November 2008 - 06:08 PM

Primes
Given two integers N and M (N <= M), output all the prime numbers between N and M inclusive, one per line.

N and M will be positive integers less than or equal to 1,000,000,000.
The difference between N and M will be less than or equal to 5,000,000.




Bills Bills Bills

A gas company has a monthly billing rate based on consumption by its customers. The rate structure is given as follows:

___________________________________________________
For the first 10m3 or less $6.59 (minimum bill)
For the next 20m3 23.73 cents/m3
For the next 55m3 22.71 cents/m3
For the next 85m3 21.78 cents/m3
For the next 170m3 20.85 cents/m3______


Write a program that will process the customers' bills. For each customer, the program should read an account number 0 <= A <= 99999 and two meter readings 0 <= M1, M2 < 10000. M1 represents the reading at the beginning of the month while M2 represents the reading at the beginning of the next month. The first line of input will be the account number. The second line of input will be M1 followed by a space then M2. The input will be terminated if and only if a negative account number is entered.

Note: There are situations where the final reading may be less than the initial reading. For example, the initial reading might be 9980 while the final reading is 0015 indicating a consumption during the month of 35m3 because the meter has 'rolled over'.
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 12 November 2008 - 07:24 AM

What do you have so far for these programs?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 JP16.1470

JP16.1470

    CC Lurker

  • Just Joined
  • Pip
  • 8 posts

Posted 12 November 2008 - 08:37 AM

I got nothin for the bills question but for the prime question i got this:

Program Prime ;
{ a program to print out all primes up to 1000
   using the Sieve of Eratosthenes.}
uses crt;
CONST 
   N = 100 ;

Var
   P     :  Array [1 .. N] of Boolean ;
   i,j,m :  Word ;

begin
   clrscr
for i := 1 TO N do
      P[i] := TRUE ;

   m := trunc(sqrt(N)) ;
   for i := 2 to m do
      if P[i] then
         for j := 2 to N DIV i do
            P[i * j] := FALSE ;

   for i := 1 to N do
      if P[i] then
         writeln(i:4) ;
end.

It works but it gives me the first 100 primes and doesnt wrk on the input of the user so if i input "4" then it still prints out all the first 100 primes when it should only output the first 4 prime numbers
  • 0

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 12 November 2008 - 10:04 AM

You need to check the value of the prime to see if it is larger than the minimum value before calling writeln.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 JP16.1470

JP16.1470

    CC Lurker

  • Just Joined
  • Pip
  • 8 posts

Posted 12 November 2008 - 02:12 PM

what do u exactly mean? can you edit the code..and fix it? PLZ THX
  • 0

#6 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 12 November 2008 - 02:27 PM


for i := 1 to N do

      if P[i] and (i>= Min) then

         writeln(i:4) ;




  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#7 JP16.1470

JP16.1470

    CC Lurker

  • Just Joined
  • Pip
  • 8 posts

Posted 12 November 2008 - 05:05 PM

In:
(i>= Min)

that it says "invalid type" on "Min".........can you please do the whole program and put it? PLZ! THX! :)
  • 0

#8 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 12 November 2008 - 05:33 PM

I am willing to help you, but not write the program for you. You need to get the minimum value into your program (as an integer) and use the comparison. Right now your program doesn't have ANYTHING that deals with the minumum value requirement.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/






Also tagged with one or more of these keywords: pascal

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download