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!!

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? Commented Nov 14, 2018 at 23:44

1 Answer 1

0
#include <stdio.h>

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

    do{
      printf("Enter the POSITIVE min value\n");
      scanf("%d\n", &min);
    }while(min < 0);

    do{
      printf("Enter the POSITIVE max value\n");
      scanf("%d\n", &max);
    }while(max < 0);

    do{
      printf("Enter the POSITIVE increment value\n");
      scanf("%d\n", &increment);
    }while(increment < 0);

    printf("%d %d %d\n", 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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.