Is this a good pseudocode and can you help me write this, I am kind of new to programming.

if (choice > 0 && choice < 4)  //choice is between 0 and 4
{
cout << "Enter the distance: \n"; //displays the distance 
cin >> distance;                  //prints the distance

if (distance > 0)
{
cout << "A sound wave takes ";     //displays the amount of time it takes a sound wave to travel 
cout << fixed << setprecision(4);  

switch (choice) // 
{ 
case 1: cout << distance / A << " seconds to travel " << distance << " feet through air.\n";
break;
case 2: cout << distance / W << " seconds to travel " << distance << " feet through water.\n";
break;
case 3: cout << distance / S << " seconds to travel " << distance << " feet through steel.\n";
break;
}
}
else 
{
cout << "Distance must be greater than zero.";  //displays that distance must be greater than zero
}
}
else 
{
cout << "The valid choices are 1 through 3. Run the program again and select one of those.";
}    //choice must be either 1,2,3 and if not, run the program again

system("pause"); //pause
return 0;
}

Edited 2 Years Ago by mike_2000_17: moved to C++ forum

What, and where is the problem in the code? Mention the problem you facing so that we can help you to solve the issue.

As pointed out, that is just bad code with no indentation, not pseudo code, which is the process of describing what the program will do, not doing it. Here is your code in pseudocode form:

    if the user inputs a valid medium
    {
        ask user to enter the distance
        get user input for distance
        if (distance > 0)
        {
            calculate the time the sound takes for the distance specified
                for the medium specified
            output the time the sound will take to traverse the medium
        }
        else
        {
            tell user they specified an invalid distance
        }
    }
    else
    {
        tell the user they chose an unsupported medium
    }

Again, the purpose of pseudocode is to tell WHAT the program should do, NOT how it should do it, though hints, suggestions, issues to address and such are ok. The idea is that the pseudocode can be commented out and the appropriate code inserted, resulting in a well-commented application.

Edited 2 Years Ago by rubberman

This article has been dead for over six months. Start a new discussion instead.