C: How to Ask the User for a Range of a Variable (that is both a Minimum and Maximum value) and an Increment...












0















I am new to coding and have started with C. In the question I am working through, it is asking to develop software that allows the user to study how the total force will vary with water depth for the type of dam presented. (total force of the pressure of water exerted on a dam)



The equation given to use is: F(d)=pg(h/2)[bd+(2Ʃw(zi)(d-zi))],

**[the sigma in the equation has index i=1(bottom of sigma) and finishes at n-1(top of sigma)]

**[this equation was determined by using the trapezoidal rule for integration]



Where,

F(d) = the total force for the depth d;
p = the density of water (assumed to be 10^3 kg/m^3);
g = acceleration due to gravity (9.8 m/s^2);
b = the width of the channel base;
d = elevation (in m) of the water above the channel bottom;
h = d/n; **(I am also confused on what n would be)**
a = is the distance from the edge of the channel base to the bank of the channel;
b = the width of the channel base;
D = the depth of the channel;
zi = z(i-1)+h for i=1,2,...,n-1;
w(zi) = (2a/D^2)(zi^2)+b


It also states... The user will provide the following input:

• dam and channel dimensions (values of a, b, D),

• the range of water depth d (that is both a minimum and maximum value for the depth),

• An increment value for the depth d to for plotting the total force ft(d) (integration is used to find the force ft for each value of the depth d).



So my question is aimed at the last two bullets above. How would I ask the user to input the range of water depth d and the increment value for d?



With the research that I have done, I believe I could create some kind of sorting function that will run a number of passes on an array (which contains the Min and Max values inputted by the user) and have the lowest number inputted as the minimum value and the largest number inputted as the maximum value. I would also need to make a loop over passes for this method to work. I could be very wrong about this as I am new to programming.



Is there an easier, less complicated way to do this? Like, would I be able to somehow simply ask the user to "enter a value for Min", "enter a value for Max" and "enter the increment value" (or something along those lines)?



Any suggestion will help, thanks in advance!!










share|improve this question























  • "would I be able to somehow simply ask the user to "enter a value for Min", "enter a value for Max" and "enter the increment value" (or something along those lines)?" Yes. What keeps you from doing just that?

    – Swordfish
    Nov 14 '18 at 23:44
















0















I am new to coding and have started with C. In the question I am working through, it is asking to develop software that allows the user to study how the total force will vary with water depth for the type of dam presented. (total force of the pressure of water exerted on a dam)



The equation given to use is: F(d)=pg(h/2)[bd+(2Ʃw(zi)(d-zi))],

**[the sigma in the equation has index i=1(bottom of sigma) and finishes at n-1(top of sigma)]

**[this equation was determined by using the trapezoidal rule for integration]



Where,

F(d) = the total force for the depth d;
p = the density of water (assumed to be 10^3 kg/m^3);
g = acceleration due to gravity (9.8 m/s^2);
b = the width of the channel base;
d = elevation (in m) of the water above the channel bottom;
h = d/n; **(I am also confused on what n would be)**
a = is the distance from the edge of the channel base to the bank of the channel;
b = the width of the channel base;
D = the depth of the channel;
zi = z(i-1)+h for i=1,2,...,n-1;
w(zi) = (2a/D^2)(zi^2)+b


It also states... The user will provide the following input:

• dam and channel dimensions (values of a, b, D),

• the range of water depth d (that is both a minimum and maximum value for the depth),

• An increment value for the depth d to for plotting the total force ft(d) (integration is used to find the force ft for each value of the depth d).



So my question is aimed at the last two bullets above. How would I ask the user to input the range of water depth d and the increment value for d?



With the research that I have done, I believe I could create some kind of sorting function that will run a number of passes on an array (which contains the Min and Max values inputted by the user) and have the lowest number inputted as the minimum value and the largest number inputted as the maximum value. I would also need to make a loop over passes for this method to work. I could be very wrong about this as I am new to programming.



Is there an easier, less complicated way to do this? Like, would I be able to somehow simply ask the user to "enter a value for Min", "enter a value for Max" and "enter the increment value" (or something along those lines)?



Any suggestion will help, thanks in advance!!










share|improve this question























  • "would I be able to somehow simply ask the user to "enter a value for Min", "enter a value for Max" and "enter the increment value" (or something along those lines)?" Yes. What keeps you from doing just that?

    – Swordfish
    Nov 14 '18 at 23:44














0












0








0








I am new to coding and have started with C. In the question I am working through, it is asking to develop software that allows the user to study how the total force will vary with water depth for the type of dam presented. (total force of the pressure of water exerted on a dam)



The equation given to use is: F(d)=pg(h/2)[bd+(2Ʃw(zi)(d-zi))],

**[the sigma in the equation has index i=1(bottom of sigma) and finishes at n-1(top of sigma)]

**[this equation was determined by using the trapezoidal rule for integration]



Where,

F(d) = the total force for the depth d;
p = the density of water (assumed to be 10^3 kg/m^3);
g = acceleration due to gravity (9.8 m/s^2);
b = the width of the channel base;
d = elevation (in m) of the water above the channel bottom;
h = d/n; **(I am also confused on what n would be)**
a = is the distance from the edge of the channel base to the bank of the channel;
b = the width of the channel base;
D = the depth of the channel;
zi = z(i-1)+h for i=1,2,...,n-1;
w(zi) = (2a/D^2)(zi^2)+b


It also states... The user will provide the following input:

• dam and channel dimensions (values of a, b, D),

• the range of water depth d (that is both a minimum and maximum value for the depth),

• An increment value for the depth d to for plotting the total force ft(d) (integration is used to find the force ft for each value of the depth d).



So my question is aimed at the last two bullets above. How would I ask the user to input the range of water depth d and the increment value for d?



With the research that I have done, I believe I could create some kind of sorting function that will run a number of passes on an array (which contains the Min and Max values inputted by the user) and have the lowest number inputted as the minimum value and the largest number inputted as the maximum value. I would also need to make a loop over passes for this method to work. I could be very wrong about this as I am new to programming.



Is there an easier, less complicated way to do this? Like, would I be able to somehow simply ask the user to "enter a value for Min", "enter a value for Max" and "enter the increment value" (or something along those lines)?



Any suggestion will help, thanks in advance!!










share|improve this question














I am new to coding and have started with C. In the question I am working through, it is asking to develop software that allows the user to study how the total force will vary with water depth for the type of dam presented. (total force of the pressure of water exerted on a dam)



The equation given to use is: F(d)=pg(h/2)[bd+(2Ʃw(zi)(d-zi))],

**[the sigma in the equation has index i=1(bottom of sigma) and finishes at n-1(top of sigma)]

**[this equation was determined by using the trapezoidal rule for integration]



Where,

F(d) = the total force for the depth d;
p = the density of water (assumed to be 10^3 kg/m^3);
g = acceleration due to gravity (9.8 m/s^2);
b = the width of the channel base;
d = elevation (in m) of the water above the channel bottom;
h = d/n; **(I am also confused on what n would be)**
a = is the distance from the edge of the channel base to the bank of the channel;
b = the width of the channel base;
D = the depth of the channel;
zi = z(i-1)+h for i=1,2,...,n-1;
w(zi) = (2a/D^2)(zi^2)+b


It also states... The user will provide the following input:

• dam and channel dimensions (values of a, b, D),

• the range of water depth d (that is both a minimum and maximum value for the depth),

• An increment value for the depth d to for plotting the total force ft(d) (integration is used to find the force ft for each value of the depth d).



So my question is aimed at the last two bullets above. How would I ask the user to input the range of water depth d and the increment value for d?



With the research that I have done, I believe I could create some kind of sorting function that will run a number of passes on an array (which contains the Min and Max values inputted by the user) and have the lowest number inputted as the minimum value and the largest number inputted as the maximum value. I would also need to make a loop over passes for this method to work. I could be very wrong about this as I am new to programming.



Is there an easier, less complicated way to do this? Like, would I be able to somehow simply ask the user to "enter a value for Min", "enter a value for Max" and "enter the increment value" (or something along those lines)?



Any suggestion will help, thanks in advance!!







c range max min






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 23:36









R. GauthierR. Gauthier

1




1













  • "would I be able to somehow simply ask the user to "enter a value for Min", "enter a value for Max" and "enter the increment value" (or something along those lines)?" Yes. What keeps you from doing just that?

    – Swordfish
    Nov 14 '18 at 23:44



















  • "would I be able to somehow simply ask the user to "enter a value for Min", "enter a value for Max" and "enter the increment value" (or something along those lines)?" Yes. What keeps you from doing just that?

    – Swordfish
    Nov 14 '18 at 23:44

















"would I be able to somehow simply ask the user to "enter a value for Min", "enter a value for Max" and "enter the increment value" (or something along those lines)?" Yes. What keeps you from doing just that?

– Swordfish
Nov 14 '18 at 23:44





"would I be able to somehow simply ask the user to "enter a value for Min", "enter a value for Max" and "enter the increment value" (or something along those lines)?" Yes. What keeps you from doing just that?

– Swordfish
Nov 14 '18 at 23:44












1 Answer
1






active

oldest

votes


















0














#include <stdio.h>

int main(void) {
int min = -1;
int max = -1;
int increment = -1;

do{
printf("Enter the POSITIVE min valuen");
scanf("%dn", &min);
}while(min < 0);

do{
printf("Enter the POSITIVE max valuen");
scanf("%dn", &max);
}while(max < 0);

do{
printf("Enter the POSITIVE increment valuen");
scanf("%dn", &increment);
}while(increment < 0);

printf("%d %d %dn", min, max, increment);
return 0;
}


Here is a sample way to get user input, where you only allow positive input. If you need to allow negative input, there are other ways to trap input errors you should look into. This doesnt handle if the user enters stupid stuff like ASDF for min depth, if that is ok this should be fine. if not you need to read all of stdin and parse it, which seems like more trouble than its worth for you at this stage :) GL with your physics homework






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310366%2fc-how-to-ask-the-user-for-a-range-of-a-variable-that-is-both-a-minimum-and-max%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    #include <stdio.h>

    int main(void) {
    int min = -1;
    int max = -1;
    int increment = -1;

    do{
    printf("Enter the POSITIVE min valuen");
    scanf("%dn", &min);
    }while(min < 0);

    do{
    printf("Enter the POSITIVE max valuen");
    scanf("%dn", &max);
    }while(max < 0);

    do{
    printf("Enter the POSITIVE increment valuen");
    scanf("%dn", &increment);
    }while(increment < 0);

    printf("%d %d %dn", min, max, increment);
    return 0;
    }


    Here is a sample way to get user input, where you only allow positive input. If you need to allow negative input, there are other ways to trap input errors you should look into. This doesnt handle if the user enters stupid stuff like ASDF for min depth, if that is ok this should be fine. if not you need to read all of stdin and parse it, which seems like more trouble than its worth for you at this stage :) GL with your physics homework






    share|improve this answer




























      0














      #include <stdio.h>

      int main(void) {
      int min = -1;
      int max = -1;
      int increment = -1;

      do{
      printf("Enter the POSITIVE min valuen");
      scanf("%dn", &min);
      }while(min < 0);

      do{
      printf("Enter the POSITIVE max valuen");
      scanf("%dn", &max);
      }while(max < 0);

      do{
      printf("Enter the POSITIVE increment valuen");
      scanf("%dn", &increment);
      }while(increment < 0);

      printf("%d %d %dn", min, max, increment);
      return 0;
      }


      Here is a sample way to get user input, where you only allow positive input. If you need to allow negative input, there are other ways to trap input errors you should look into. This doesnt handle if the user enters stupid stuff like ASDF for min depth, if that is ok this should be fine. if not you need to read all of stdin and parse it, which seems like more trouble than its worth for you at this stage :) GL with your physics homework






      share|improve this answer


























        0












        0








        0







        #include <stdio.h>

        int main(void) {
        int min = -1;
        int max = -1;
        int increment = -1;

        do{
        printf("Enter the POSITIVE min valuen");
        scanf("%dn", &min);
        }while(min < 0);

        do{
        printf("Enter the POSITIVE max valuen");
        scanf("%dn", &max);
        }while(max < 0);

        do{
        printf("Enter the POSITIVE increment valuen");
        scanf("%dn", &increment);
        }while(increment < 0);

        printf("%d %d %dn", min, max, increment);
        return 0;
        }


        Here is a sample way to get user input, where you only allow positive input. If you need to allow negative input, there are other ways to trap input errors you should look into. This doesnt handle if the user enters stupid stuff like ASDF for min depth, if that is ok this should be fine. if not you need to read all of stdin and parse it, which seems like more trouble than its worth for you at this stage :) GL with your physics homework






        share|improve this answer













        #include <stdio.h>

        int main(void) {
        int min = -1;
        int max = -1;
        int increment = -1;

        do{
        printf("Enter the POSITIVE min valuen");
        scanf("%dn", &min);
        }while(min < 0);

        do{
        printf("Enter the POSITIVE max valuen");
        scanf("%dn", &max);
        }while(max < 0);

        do{
        printf("Enter the POSITIVE increment valuen");
        scanf("%dn", &increment);
        }while(increment < 0);

        printf("%d %d %dn", min, max, increment);
        return 0;
        }


        Here is a sample way to get user input, where you only allow positive input. If you need to allow negative input, there are other ways to trap input errors you should look into. This doesnt handle if the user enters stupid stuff like ASDF for min depth, if that is ok this should be fine. if not you need to read all of stdin and parse it, which seems like more trouble than its worth for you at this stage :) GL with your physics homework







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 0:02









        BwebbBwebb

        5009




        5009
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310366%2fc-how-to-ask-the-user-for-a-range-of-a-variable-that-is-both-a-minimum-and-max%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Error while running script in elastic search , gateway timeout

            Adding quotations to stringified JSON object values