Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 894153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:20:12+00:00 2026-05-15T14:20:12+00:00

Being new to Ada, I’m exploring its syntax and rules and I would like

  • 0

Being new to Ada, I’m exploring its syntax and rules and I would like to draw attention on the code given next. Here I’m trying to set a variable Actual_Stiffness to hold a constant value. Its value is given by the product:

Actual_Stiffness := Stiffness_Ratio * Stiffness_Total

where Stiffness_Total has been defined to be a constant Long_Float in the specification file Material_Data.ads and Stiffness_Total has a value already set in the ads file.

WITH Ada.Text_IO;
WITH Ada.Long_Float_Text_IO;
WITH Material_Data;
USE Material_Data;

PROCEDURE sample IS

   Stiffness_Ratio  : Long_Float;
   Actual_Stiffness : CONSTANT Long_Float :=  Stiffness_Ratio * Stiffness_Total;

BEGIN -- main program
   Ada.Text_IO.Put("Enter stiffness ratio: ");
   Ada.Long_Float_Text_IO.Get(Item => Stiffness_Ratio);
   Ada.Long_Float_Text_IO.Put(Item => Stiffness_Ratio);

   --Ada.Text_IO.New_Line;
   --Ada.Long_Float_Text_IO.Put(Item => Actual_Stiffness);
   --Ada.Text_IO.New_Line;
   --Ada.Long_Float_Text_IO.Put(Item => Stiffness_Total);
END sample;

On compiling I get the warning message

warning: “Stiffness_Ratio” may be referenced before it has a value

and on running the program, Actual_Stiffness doesn’t get the right value. I could defined Actual_Stiffness to be just a Long_Float (without adding CONSTANT) and then get its value from the product Actual_Stiffness := Stiffness_Ratio * Stiffness_Total after BEGIN in my program when Stiffness_Ratio would have already gotten a value. This would be the right thing to do.

My question is:

I have defined Stiffness_Total as a constant Long_Float with a prescribed value. How to define Actual_Stiffness to be constant also (as it won’t be changing in the program) while keeping the ability for a user to interactively being able to enter a Stiffness_Ratio at the terminal? Is that even possible to do?

Thanks a lot..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:20:12+00:00Added an answer on May 15, 2026 at 2:20 pm

    Since the ‘Stiffness_Ratio’ is not determined until run-time, the compiler cannot calculate the value of ‘Actual_Stiffness’ at compile time as you have asked it to. You will have to make ‘Actual_Stiffness’ into a non-constant variable and initialize it with the computation after ‘Stiffness_Ratio’ has a value. (You may even be able to keep it as a CONSTANT within the function as long as the stiffness ratio has a value at the time the actual stiffness is computed.)

    This is standard in most programming languages.

    So, to answer your question:

    • No, you cannot define Actual_Stiffness as a constant as desired.

    • A moderately close approximation is that you determine the Stiffness_Ratio value outside this procedure, and pass that value into the procedure as a parameter. But then the Actual_Stiffness is only constant for the duration of the procedure, not for all time.

    On the other hand, this is likely to be more useful; someone can run the program with multiple values of the stiffness ratio at different times, thus doing many simulations in a single run.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.