Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Beginners help please.

gooshgoosh Posts: 11Member
Hi can anyone tell me how to get the region sales to calculete the whole 8 inputs? What it seems is happening is the a integer is repeating untill 8 but that the program stops at 8 and only adds the first 7. If I put repeat untill a > 8 then it still asks for the 9th region although it does calculate the first 8 which is what I want it to do.
program regions;

var

a:integer;
region_sales, total_sales:real;

procedure init;
begin
region_sales := 0.0;
total_sales := 0.0;
a := 0;
end;

procedure get_sales;
begin
writeln ('Please enter sales for region ',a);
readln (region_sales);
end;

procedure print_sales;
begin
writeln ('The sales for all regions were ',total_sales:6:2);
end;

begin
init;
repeat

a := a + 1;
total_sales := total_sales + region_sales;
get_sales;
until a = 8;
print_sales;

end.

Thanks for any help :)

Oh yeah and I tried using the while statement (while total_sales > 9 do) but that keeps asking me for the 9th region before calculating the first 8 too.



Comments

  • PerranPerran Posts: 241Member
    : Hi can anyone tell me how to get the region sales to calculete the whole 8 inputs? What it seems is happening is the a integer is repeating untill 8 but that the program stops at 8 and only adds the first 7. If I put repeat untill a > 8 then it still asks for the 9th region although it does calculate the first 8 which is what I want it to do.
    : program regions;
    :
    : var
    :
    : a:integer;
    : region_sales, total_sales:real;
    :
    : procedure init;
    : begin
    : region_sales := 0.0;
    : total_sales := 0.0;
    : a := 0;
    : end;
    :
    : procedure get_sales;
    : begin
    : writeln ('Please enter sales for region ',a);
    : readln (region_sales);
    : end;
    :
    : procedure print_sales;
    : begin
    : writeln ('The sales for all regions were ',total_sales:6:2);
    : end;
    :
    : begin
    : init;
    : repeat
    :
    : a := a + 1;
    : total_sales := total_sales + region_sales;
    : get_sales;
    : until a = 8;
    : print_sales;
    :
    : end.
    :
    : Thanks for any help :)
    :
    : Oh yeah and I tried using the while statement (while total_sales > 9 do) but that keeps asking me for the 9th region before calculating the first 8 too.
    :
    :
    :
    :
    You need to place your call to get_sales before the line that adds the region_sales to the total. HTH
  • gooshgoosh Posts: 11Member
    : : Hi can anyone tell me how to get the region sales to calculete the whole 8 inputs? What it seems is happening is the a integer is repeating untill 8 but that the program stops at 8 and only adds the first 7. If I put repeat untill a > 8 then it still asks for the 9th region although it does calculate the first 8 which is what I want it to do.
    : : program regions;
    : :
    : : var
    : :
    : : a:integer;
    : : region_sales, total_sales:real;
    : :
    : : procedure init;
    : : begin
    : : region_sales := 0.0;
    : : total_sales := 0.0;
    : : a := 0;
    : : end;
    : :
    : : procedure get_sales;
    : : begin
    : : writeln ('Please enter sales for region ',a);
    : : readln (region_sales);
    : : end;
    : :
    : : procedure print_sales;
    : : begin
    : : writeln ('The sales for all regions were ',total_sales:6:2);
    : : end;
    : :
    : : begin
    : : init;
    : : repeat
    : :
    : : a := a + 1;
    : : total_sales := total_sales + region_sales;
    : : get_sales;
    : : until a = 8;
    : : print_sales;
    : :
    : : end.
    : :
    : : Thanks for any help :)
    : :
    : : Oh yeah and I tried using the while statement (while total_sales > 9 do) but that keeps asking me for the 9th region before calculating the first 8 too.
    : :
    : :
    : :
    : :
    : You need to place your call to get_sales before the line that adds the region_sales to the total. HTH
    :
    Oh that's wild! Thanks for your reply! That works but I can't believe I didn't see that lol. I hope you answer my next question although I do want to learn it myself but my syntax is so bad. Thanks again :)

  • gooshgoosh Posts: 11Member
    : : : Hi can anyone tell me how to get the region sales to calculete the whole 8 inputs? What it seems is happening is the a integer is repeating untill 8 but that the program stops at 8 and only adds the first 7. If I put repeat untill a > 8 then it still asks for the 9th region although it does calculate the first 8 which is what I want it to do.
    : : : program regions;
    : : :
    : : : var
    : : :
    : : : a:integer;
    : : : region_sales, total_sales:real;
    : : :
    : : : procedure init;
    : : : begin
    : : : region_sales := 0.0;
    : : : total_sales := 0.0;
    : : : a := 0;
    : : : end;
    : : :
    : : : procedure get_sales;
    : : : begin
    : : : writeln ('Please enter sales for region ',a);
    : : : readln (region_sales);
    : : : end;
    : : :
    : : : procedure print_sales;
    : : : begin
    : : : writeln ('The sales for all regions were ',total_sales:6:2);
    : : : end;
    : : :
    : : : begin
    : : : init;
    : : : repeat
    : : :
    : : : a := a + 1;
    : : : total_sales := total_sales + region_sales;
    : : : get_sales;
    : : : until a = 8;
    : : : print_sales;
    : : :
    : : : end.
    : : :
    : : : Thanks for any help :)
    : : :
    : : : Oh yeah and I tried using the while statement (while total_sales > 9 do) but that keeps asking me for the 9th region before calculating the first 8 too.
    : : :
    : : :
    : : :
    : : :
    : : You need to place your call to get_sales before the line that adds the region_sales to the total. HTH
    : :
    : Oh that's wild! Thanks for your reply! That works but I can't believe I didn't see that lol. I hope you answer my next question although I do want to learn it myself but my syntax is so bad. Thanks again :)
    :
    :
    Hi can anyone give me any hints as in how to add 4 quarters to this code? I would prefer it to say region 1 1st quarter region 2 second quarter then up to region 8 4th quarter but i don't know how to get the quarter loops? Thanks for any idea

  • PerranPerran Posts: 241Member
    : : : : Hi can anyone tell me how to get the region sales to calculete the whole 8 inputs? What it seems is happening is the a integer is repeating untill 8 but that the program stops at 8 and only adds the first 7. If I put repeat untill a > 8 then it still asks for the 9th region although it does calculate the first 8 which is what I want it to do.
    : : : : program regions;
    : : : :
    : : : : var
    : : : :
    : : : : a:integer;
    : : : : region_sales, total_sales:real;
    : : : :
    : : : : procedure init;
    : : : : begin
    : : : : region_sales := 0.0;
    : : : : total_sales := 0.0;
    : : : : a := 0;
    : : : : end;
    : : : :
    : : : : procedure get_sales;
    : : : : begin
    : : : : writeln ('Please enter sales for region ',a);
    : : : : readln (region_sales);
    : : : : end;
    : : : :
    : : : : procedure print_sales;
    : : : : begin
    : : : : writeln ('The sales for all regions were ',total_sales:6:2);
    : : : : end;
    : : : :
    : : : : begin
    : : : : init;
    : : : : repeat
    : : : :
    : : : : a := a + 1;
    : : : : total_sales := total_sales + region_sales;
    : : : : get_sales;
    : : : : until a = 8;
    : : : : print_sales;
    : : : :
    : : : : end.
    : : : :
    : : : : Thanks for any help :)
    : : : :
    : : : : Oh yeah and I tried using the while statement (while total_sales > 9 do) but that keeps asking me for the 9th region before calculating the first 8 too.
    : : : :
    : : : :
    : : : :
    : : : :
    : : : You need to place your call to get_sales before the line that adds the region_sales to the total. HTH
    : : :
    : : Oh that's wild! Thanks for your reply! That works but I can't believe I didn't see that lol. I hope you answer my next question although I do want to learn it myself but my syntax is so bad. Thanks again :)
    : :
    : :
    : Hi can anyone give me any hints as in how to add 4 quarters to this code? I would prefer it to say region 1 1st quarter region 2 second quarter then up to region 8 4th quarter but i don't know how to get the quarter loops? Thanks for any idea
    :
    :
    If you just want to track totals use an array like:
    [code]
    total_sales : array[1..4,1..8] of real;
    [/code]
    You will then need to use nested loops to go thru the array as:
    [code]
    for i:=1 to 4 do
    for j:=1 to 8 do //blah blah
    [/code]
    If you decide to keep adding information you might want to consider learning about records. HTH

Sign In or Register to comment.