Summation loop program in Pascal
        Posted  
        
            by 
                user2526598
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user2526598
        
        
        
        Published on 2013-06-27T04:48:59Z
        Indexed on 
            2013/06/27
            10:21 UTC
        
        
        Read the original article
        Hit count: 362
        
pascal
|nested-loops
I am having a bit of an issue with this problem. I am taking a Pascal programming class and this problem was in my logic book. I am required to have the user enter a series of (+) numbers and once he/she enters a (-) number, the program should find the sum of all the (+) numbers. I accomplished this, but now I am attempting part two of this problem, which requires me to utilize a nested loop to run the program x amount of times based on the user's input.
The following code is what I have so far and honestly I am stumped:
program summation;
//Define main program's variables
var num, sum, numRun : integer;
//Design procedure that will promt user for number of runs
procedure numRunLoop ( var numRun : integer );
  begin
    writeln('How many times shall I run this program?');
    readln(numRun);
  end;
//Design procedure that will sum a series of numbers
//based on user input
procedure numPromptLoop( numRun : integer; var num : integer );
var count : integer;
  begin
    //Utilize for to establish run limit
    for count := 1 to numRun do
      begin
        //Use repeat to prompt user for numbers
        repeat
          writeln('Enter a number: ');
          readln(num);
          //Tells program when to sum
          if num >= 0 then
             sum := sum + num;
        until num < 0;
    end;
  end;
//Design procedure that will display
procedure addItion( sum : integer );
  begin
    writeln('The sum is; ', sum);
  end;
begin
numRunLoop(numRun);
numPromptloop(numRun, num);
addItion(sum);
readln();
end.
© Stack Overflow or respective owner