I just started programming in C our first asssignment is writing an alogrithm to compute the volume of water in cubic feet, flowing through a pipe of diameter d in feet, with a velocity of v feet per second, give this fomula

r=d/2
area=pi x r squared
volume = area x v

Below i have gotten written in the C source code, my instructor says to write the algorithm like a person normally does,
So does that mean pseudo code or a flowchart or a structure chart? If it is pseudo code how do i do that, we haven't covered anything about writing in pseudo code.

int main() {

    double d;//Variable to store value of diameter variable
    double v;//Variable to store value of Velocity
    double r, PI, area, volume;

    printf("Enter a value for diameter : ");//Prompts the user to enter diameter
    scanf("%lf", &d);//Saves the value entered by user to d variable

    printf("Enter a value for velocity : ");//Prompts the user to enter velocity
    scanf("%lf", &v);//Stores value to variable v

    r = d/2.0;  // Calculates value of r 
    PI = 3.14;  //Constant PI
    area = PI*r*r; //Calculates area and store sin variable named area
    volume = area*v; //Calculates volume and stores in variable named volume


    printf("Volume of water flow is : %f\n" , volume);//Prints the value of volume variable

    system("PAUSE");
    return 0;//Exit

Pseudo code, Flow charts, etc are nothing more than a human legible medium to stage the logic so that it can then be translated into code.

For instance you can translate this human readable line...

Ask the user for a floating point number

into this code...

printf("Prompt: ");
scanf("%f", &Variable);

The nice thing about pseudo code is that it can be as general or detailed as you want. Its up to you to decide how to translate it to code. Equally nice about simple algebra like you are doing is that it translates very well into programming. More complex formulas may involve writing functions to facilitate specific aspects of the procedure, but that is not something you usually think about in the flowchart / pseudo code process.

I guess you could think of it like a language translation between English to Computer.

For your program, pseudo-code might look like:

Get diameter from user
Get velocity from user

radius = diameter / 2.0
PI = 3.14
area = PI * radius * radius
volume = area * velocity

Print volume of water flow

In pseudo-code, you don't worry about how to properly write the syntax,
such as

    if (x == 1)
    {
       return;
    }//

you can just write

if x = 1, then return
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.