+ Reply to Thread
Results 1 to 8 of 8

Thread: Pascal program that inputs an integer larger than 1

  1. #1
    Newbie sobi is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    9

    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. #2
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    37
    Posts
    12,912
    Blog Entries
    57

    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.
    CodeCall Blog | CodeCall Wiki
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  3. #3
    Newbie sobi is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    9

    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.

  4. #4
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    37
    Posts
    12,912
    Blog Entries
    57

    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);
    CodeCall Blog | CodeCall Wiki
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  5. #5
    Newbie sobi is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    9

    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.

  6. #6
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    37
    Posts
    12,912
    Blog Entries
    57

    Re: Pascal program that inputs an integer larger than 1

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

  7. #7
    Programmer 2710 is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    108

    Re: Pascal program that inputs an integer larger than 1

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

  8. #8
    Newbie sobi is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    9

    Re: Pascal program that inputs an integer larger than 1

    Thanks all,finally it worked.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Replies: 8
    Last Post: 12-16-2009, 11:53 AM
  2. Tutorial: Starting C# with C# 2008 Express Edition
    By Jordan in forum CSharp Tutorials
    Replies: 20
    Last Post: 07-27-2009, 01:45 AM
  3. Debugging a C++/C File with GDB Debugger
    By awesome001 in forum C and C++
    Replies: 2
    Last Post: 01-01-2009, 05:07 PM
  4. Help with SendMessage API
    By MrNobody in forum Visual Basic Programming
    Replies: 8
    Last Post: 11-22-2006, 10:01 AM