Hey so heres a simple program I'm making that has to calculate a number from different inputs by the user.

It worked for a bit, but now when executed the command prompt screen comes up but its blank, then I try to close it and it stops responding. Then when it finally does close I try and run again and I get a POLINK ACCESS DENIED ERROR (1).

What could be causing my program to not respond all of a sudden?


Im thinking my loop may be faulty?? Could anyone help?

#include <stdio.h>
#include <math.h>

int main(void)
{
    double pr_drop, flow_rate_p, diameter_p, roughness_p, ci_age, material_p;
//Just naming the variables
    printf("In gallons/min, what is the flow rate: ");
    scanf("%lf", &flow_rate_p);
//Asks the user what the flowrate is, and then stores it under flow_rate_p
    printf("In inches, what is the diameter of your pipe: ");
    scanf("%lf", &diameter_p);
//Asks the user what the diameter of the pipe is and stores it as diameter_p
    printf("What material is your pipe made of? The materials are organized as: 1 for Concrete, 2 for Copper, 3 for Steel, 4 for PVC, 5 for Cast iron\n");
//Asks the user what the pipe is made of, gives several options.
    do
    {
            printf("Please enter the appropriate number (only integer values from 1 to 5 are accepted):");
            scanf("%lf", &material_p);
//Stores the users input at material_p
    } while (material_p < 1 || material_p > 5 || (material_p > 1 && material_p < 2) || (material_p > 2 && material_p < 3) || (material_p > 3 && material_p < 4) || (material_p > 4 && material_p < 5));

    do
    {
        if (material_p == 1)
           roughness_p = 100;
        else if (material_p == 2)
           roughness_p = 150;
        else if (material_p == 3)
           roughness_p = 120;
        else if (material_p == 4)
           roughness_p = 150;
        else if (material_p == 5)
        {
           printf("What is the age of your pipe? ");
           scanf("%lf", &ci_age);
               if (ci_age >= 0 && ci_age < 5)
                   roughness_p = 130;
               else if (ci_age >= 5 && ci_age < 15)
                   roughness_p = 110;
               else if (ci_age >= 15 && ci_age < 25)
                   roughness_p = 95;
               else if (ci_age >= 25 && ci_age <35)
                   roughness_p = 83;
               else if (ci_age >= 25 && ci_age <=40)
                   roughness_p = 70;
               else if (ci_age > 40 || ci_age < 0)
                   printf(" Between 0 and 40, please enter number of years; if your pipe is older than 40 years, get a new one.\n");
//If the user doesnt enter a number between 0 and 40 this error message will appear.
        }
    } while ((material_p == 5 && ci_age < 0) || (material_p == 5 && ci_age > 40));

    pr_drop = (4.52* pow(flow_rate_p,1.85))/(pow(roughness_p, 1.85)*pow(diameter_p, 4.87));

    printf("Your system's pressure drop is about: %.4lf psi/foot\n", pr_drop);
//Calculates the pressure drop for the user
    return 0;

}

I compiled it with VC++ 2008 Express on Vista Home and got the below output. Didn't get the error you reported.

In gallons/min, what is the flow rate: 1
In inches, what is the diameter of your pipe: 2
What material is your pipe made of? The materials are organized as: 1 for Concre
te, 2 for Copper, 3 for Steel, 4 for PVC, 5 for Cast iron
Please enter the appropriate number (only integer values from 1 to 5 are accepte
d):
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.