Closed Thread
Results 1 to 8 of 8

Thread: Pascal program that inputs an integer larger than 1

  1. #1
    sobi is offline Newbie
    Join Date
    Apr 2009
    Posts
    9
    Rep Power
    0

    Pascal program that inputs an integer larger than 1

    New to this forum and fairly new in pascal. Trying to solve this problem. A pascal program that inputs an integer larger than 1 and calculates the sum of the squares from 1 to that integer.For example, if the integer is 4, the sum of the squares is 30(1+4+9+16).The output is to be the value of the integer and the sum.
    This is what I have done so far, but the program isn't giving me what i want.Any ideas please?
    Code:
    program Untitled;
    
    VAR
      Square,
      Integer_Value,
        Sum,
          Count:
            Integer;
    
       BEGIN
          Count := 0;
          Sum := 0;
          Writeln('Enter integer value');
          Readln(Integer_Value);
          WHILE Count <= Integer_Value DO
           BEGIN
            Read(Integer_Value);
            Square := (Count * Count);
            Sum := Sum + Square;
            Count := Count + 1;
           Writeln('Sum');
           Writeln('Integer_Value');
           END
    
    
    
    END.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Pascal program that inputs an integer larger than 1

    Why are you re-reading Integer_Value inside your while loop? Get rid of that line and you should be in good shape. Also, move the writeln's outside the while loop, or they'll print for every intermediate step.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    sobi is offline Newbie
    Join Date
    Apr 2009
    Posts
    9
    Rep Power
    0

    Re: Pascal program that inputs an integer larger than 1

    Did some changes based on the comments but still have an error.Having errors with the last 2 writeln statements.
    Here is the code:
    Code:
    program Untitled;
    
    VAR
      Square,
      Integer_Value,
        Sum,
          Count:
            Integer;
    
       BEGIN
          Count := 0;
          Sum := 0;
          Writeln('Enter integer value');
          Readln(Integer_Value);
          WHILE Count <= Integer_Value DO
           BEGIN
            Square := (Count * Count);
            Sum := Sum + Square;
            Count := Count + 1;
            END
          Writeln('Sum');
          Writeln('Integer_Value');
    
    
    
    END.

  5. #4
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Pascal program that inputs an integer larger than 1

    You're writing out a string, but not the variables themselves.
    Code:
          Writeln('Sum: ',Sum);
          Writeln('Integer_Value: ',Integer_value);
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  6. #5
    sobi is offline Newbie
    Join Date
    Apr 2009
    Posts
    9
    Rep Power
    0

    Re: Pascal program that inputs an integer larger than 1

    Still have an error on the last two writelns.
    Code:
    program Untitled;
    
    VAR
      Square,
      Integer_Value,
        Sum,
          Count:
            Integer;
    
       BEGIN
          Count := 0;
          Sum := 0;
          Writeln('Enter integer value' );
          Readln(Integer_Value);
          WHILE Count <= Integer_Value DO
           BEGIN
            Square := (Count * Count);
            Sum := Sum + Square;
            Count := Count + 1;
            END
          Writeln('Sum: ', Sum);
          Writeln('Integer_Value: ',Integer_Value);
    
    
    
    END.

  7. #6
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Pascal program that inputs an integer larger than 1

    What is the error?
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  8. #7
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: Pascal program that inputs an integer larger than 1

    You missed a semicolon. Above the writeln and after the END

  9. #8
    sobi is offline Newbie
    Join Date
    Apr 2009
    Posts
    9
    Rep Power
    0

    Re: Pascal program that inputs an integer larger than 1

    Thanks all,finally it worked.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. declaring an integer in a C program
    By onus in forum C and C++
    Replies: 2
    Last Post: 11-23-2010, 05:58 AM
  2. Test inputs help please.
    By patience in forum General Programming
    Replies: 1
    Last Post: 03-16-2007, 10:45 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts