❌ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Before yesterdayNews from the Ada programming language world

object "Antal_rader" cannot be used before end of its declaration

OBS! My code is written with Swedish terms.

I have to code a VAT table but i have run in to some problems concerning Floats and the way that it rounds values. At first, I was using a while loop but that didn't work since it (after a while) got too affected by the float-issue.

I created a For-loop instead which in theory should work better. However. I'm having an issue with one of my variables.

The variable "Antal_Rader" is being declared before the For-loop but i still get the error code: "object "Antal_rader" cannot be used before end of its declaration"

Code:

with Ada.Text_IO;              use Ada.Text_IO;
with Ada.Float_Text_IO;        use Ada.Float_Text_IO;

procedure Momstabellen is
   Forsta_Pris : Float;
   Sista_Pris : Float;
   Steglangd : Float;
   Momsprocent : Float;
   Moms : Float;
   Antal_Rader : Float;
   Nuvarande_Rad : Float;
   
   
begin
   -- 1. Ta emot alla variabler för momstabellen:
   Put("Första pris: ");
   Get(Forsta_Pris);
   while Forsta_Pris < 0.0 loop
      Put("Felaktigt värde!");
      New_Line;
      Put("Första pris: ");
      Get(Forsta_Pris);
    end loop;
   
   Put("Sista pris: ");
   Get(Sista_Pris);
   while Sista_Pris < Forsta_Pris loop
      Put("Felaktigt värde!");
      New_Line;
      Put("Sista pris: ");
      Get(Sista_Pris);
   end loop;
   
   Put("Steg: ");
   Get(Steglangd);
   while Steglangd < 0.0 loop
      Put("Felaktigt värde!");
      New_Line;
      Put("Steg: ");
      Get(Steglangd);
   end loop;
   
   Put("Momsprocent: ");
   Get(Momsprocent);
   while Momsprocent < 0.0 or Momsprocent > 100.0 loop
      Put("Felaktigt värde!");
      New_Line;
      Put("Momsprocent: ");
      Get(Momsprocent);
   end loop;
   New_Line;

-- 2. Skapa en layout för momstabellen:
   Put("============ Momstabell ============");
   New_Line;
   Put("Pris utan moms  Moms   Pris med moms");
   New_Line;

Issue lies here:

   

   Antal_Rader := (Sista_Pris - Forsta_Pris)/Steglangd;
   
   for I in 0 .. Antal_Rader loop
      
      Nuvarande_Rad := Antal_Rader * Steglangd + Forsta_Pris;   
      Moms := Nuvarande_Rad/100.0 * Momsprocent;
      
      Put(Nuvarande_Rad, Fore=> 6, Aft => 2, Exp => 0);
      Put(Moms, Fore => 8, Aft => 2, Exp => 0);
      Put(Nuvarande_Rad + Moms, Fore => 9, Aft => 2, Exp => 0);
     
   end loop;
    
     
end Momstabellen;

I have tried changing the first line of the For-loop and also tried changing the position of "Antal_Rader" but nothing has worked.

I am quite new to this so i can't think of many more things to do.

Why does Ada Language use Semicolon `;` to Separate Parameters in Subprogram Declarations?

fellow coders..

I'm just a new learner and try to practice some programming paradigms in their specific designed environments. Recently I've learn quite many new small things in Procedural Programming in Ada Language and have a great experience of learning. But, I cannot find the answer by myself for the wonder why Ada does use Semicolons ; to separate Parameters in Subprogram Declarations.

-- subprogram declaration - - - - - - - - -

procedure Initialize_Some_Things
   ( Result : out Integer
   ; Asset : in Integer
   ; Option: in Integer ) is
begin
   null;
end Initialize_Some_Things;

-- invoking subprogram - - - - - - - - -

Instance : Integer := 0;
Initialize_Some_Things (Instance, 9, 5);

It's obviously strange for anyone who comes from any other programming language to use a Semicolon to Separate Parameters in Subprogram Declaration though. And it's even more strange when the Invocations of Subprograms require to use Comma , instead of Semicolon ; as in Declarations. I've searched for related questions for sometime and find nothing on the Google. Is there anyway to submit a request to make this subtle change to the standard specification of the language?

I've found no related question on Google. And I hope I can find here.

❌
❌