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

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

    return 0;//Exit
3 Years
Discussion Span
Last Post by cgeier

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.

Edited by N1GHTS


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)

you can just write

if x = 1, then return

Edited by cgeier: comment

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.