I'm having the most difficult time trying to word pseudo code for this program i have. When I start to write the p.code it's like i don't know how to word it. I understand its just like translating the language to terms where non programers can understand it. but i've never really had to write p.code until now so that i can understand how to write it in the future if im recommended to. The program is just something i threw together to see if i could write p.code...If someone could like walk me through this it will be greatly appreciated. I've read books but it just confuses me more. The program just basically add or subtract numbers as if you were adding your monthly bills together to see exactly what you have to spend or have spent on monthly bills.....

Here's the code:

using System;

namespace Addingnumbers
{

    public delegate int mathsOp(int value1, int value2, int value3, int value4);

    class MathClass
    {

        public int add(int value1, int value2, int value3, int value4)
        {
            return value1 + value2 + value3 + value4;
        }

        public int sub(int value1, int value2, int value3, int value4)
        {
            return value1 - value2 - value3 - value4;
        }

    }

    class MainClass
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("This is a program that will add your monthly bills with the option to subtract.....");

            Console.WriteLine("Whole numbers Only");

            MathClass mathFunc = new MathClass();

            mathsOp theMathOp;


            Console.Write("Please enter bill total 1 : ");
            int inputValue1 = Convert.ToInt16(Console.ReadLine());
            Console.Write("Please enter bill total 2 : ");
            int inputValue2 = Convert.ToInt16(Console.ReadLine());
            Console.Write("Please enter bill total 3 : ");
            int inputValue3 = Convert.ToInt16(Console.ReadLine());
            Console.Write("Please enter bill total 4 : ");
            int inputValue4 = Convert.ToInt16(Console.ReadLine());

            Console.WriteLine("Please enter maths function :");
            Console.WriteLine("1 : add");
            Console.WriteLine("2 : sub");
            int mathsInputFun = Convert.ToInt16(Console.ReadLine());

            switch (mathsInputFun)
            {
                case 1:
                    theMathOp = new mathsOp(mathFunc.add);
                    break;
                case 2:
                    theMathOp = new mathsOp(mathFunc.sub);
                    break;
                default:
                    Console.WriteLine("Settings to add");
                    theMathOp = new mathsOp(mathFunc.add);
                    break;
            }

            Console.WriteLine(" Bill 1 = " + inputValue1 + (mathsInputFun == 1 ? " + " : " - ")
                              + " Bill 2 = " + inputValue2 + " Bill 3 = " + inputValue3 + " Bill 4 =  " + inputValue4 );


            Console.WriteLine(theMathOp(inputValue1, inputValue2, inputValue3, inputValue4));
        }
    }
}

I'm confused here... you have actual code and you want to convert it to pseudocode?

I think you may have misunderstood the concept of pseudocode...you have the right idea, that non-programmers can read it and understand it, but that isnt its purpose.
The idea is to write the pseudocode BEFORE you write your code. You use pseudocode to get a view of the flow of your app. Short english phrases to state what the program should do at each stage of execution.
Pseudocode is a means of planning your application without getting caught up in syntax. You focus on WHAT it needs to do and leave HOW it does it for later.
A correctly written pseudocode can form a basic class outline when you do it right :)

commented: Well explained! +7
commented: :) +1

I know I'm suppose to write the pseudocode before i write the code. But I DON'T understand exactly how to write the pseudocode. I just started this programming thing a few months ago. And i would always do my actual code with out pseudocode but it explains why i was always stuck checking errors. So now I'm paying for what i didn't do when i started out. I have the slightest clue how to write p.code. sometime i find it helpful to me to work backwards as this is what im use to...

If anyone know of any programs that have the p.code and the actual code, where i can study it so that i'll understand exactly what i need to do to learn how to write p.code, and adapt to writting the p.code before my program......

One example of pseudocode would be this.

Another would be this.

Basically a step by step breakdown of the steps required to achieve the task you're working on from which you can build your actual code. It can also be achieved through diagrams and flowcharts, whatever helps you illustrate the steps and logic required.

Hope that helps :)

Edit: nick's post above has a couple of decent resource links for learning about pseudocode as well if you care to look at them.

If anyone know of any programs that have the p.code and the actual code, where i can study it so that i'll understand exactly what i need to do to learn how to write p.code, and adapt to writting the p.code before my program......

While I don't have any side-by-side examples to provide I'll try to give a bit more detailed explanation of the process from my own understanding with a generalized example.

Let's assume you have a lemonade stand (ya, like one of those needs a software designed for it but we'll go with it anyway cus I'm not feeling very creatively inspired).

For each glass of lemonade sold you charge $0.50, there are 10 glasses in a pitcher and a pitcher costs $2.00 to make. You've purchased enough ingredients to make 40 pitchers and you want to track your sales but also have the software tell you when you've 'broken even' on your costs.

P.Code:
--Initial Setup--

  1. Prompt user for total investment in ingredients (in this scenario input will be $80.00)
  2. Prompt user for cost per glass (in this scenario input will be $0.50)
  3. Determine break-even point (investment/cost)

--Start Program--

  1. Prompt for number of glasses sold for each transaction (request 'Enter # of glasses sold')
  2. Calculate cost of current sale (number * cost)
  3. Add to running total (totalCost += cost)
  4. Display running total (output totalCost)
  5. Check if running total is equal or greater than target (if (totalCost >= investment))
  6. If true, inform that goal is met and begin loop again (display 'broke even on cost' & resume loop)
  7. If false, resume loop

Basically in this example what we did was break down the step by step requirements in order to fulfill the end result that we required. In order to determine when we've broken even on lemonade sales we need to determine the investment we've made, the cost per unit of sale and how many sales it would take to meet that investment. We then require a method for tracking the sales and the current place within the target. Finally we require some sort of trigger to determine whether we've reached that target.

To turn the same thing into C# code... Keep in mind the following is a SIMPLE console app with no input error checking or validation processes and is only to illustrate the conversion from pseudocode to actual code:

double investment = 0;
        double costPer = 0;
        int breakEven = 0;
        double currCost = 0;
        double runningTotal = 0;

        private void LStandRegister()
        {
            Console.WriteLine("Enter total cost for ingredients: ");
            investment = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Enter cost per glass: ");
            costPer = Convert.ToDouble(Console.ReadLine());
            breakEven = Convert.ToInt16(investment / costPer);
            bool standOpen = true;
            while (standOpen == true)
            {
                Console.WriteLine("Enter number of glasses in this transaction: ");
                currCost = Convert.ToDouble(Console.ReadLine()) * costPer;
                runningTotal += currCost;
                Console.WriteLine("Current Sale: " + currCost + " Total Sales: " + runningTotal);
                if (runningTotal >= investment)
                {
                    Console.WriteLine("Broke Even on Cost of Ingredients!");
                }
                Console.WriteLine("Another sale?");
                string contSales = Console.ReadLine();
                if (contSales == "y")
                {
                    continue;
                }
                else
                {
                    standOpen = false;
                }
            }
        }

Hope that helps to understand the pseudocode process a bit better for you :) Please remember to mark as solved once your issue is resolved.

commented: very well written example :) +1
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.