Closed Thread
Results 1 to 2 of 2

Thread: Pseudocode

  1. #1
    roman55 is offline Newbie
    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Pseudocode

    Below is the pseudocode to the first program I have completely authored for my computer science class. The instructions were very vague. We haven't even seen pseudocode in class. If anyone has any suggests for me that would be great. Thank you.

    The program finds the most efficient number of boxes and the total cost for the entered amount of coffee bags. Large boxes hold 20, medium hold 10, and small hold 5. The pricing is all at the end.

    Code:
    get Bags from user
    
    IF Bags ≥ 20
    Divide Bags by 20
    Large = +Integer
    
    IF 10 ≤ Bags < 20
    	Divide Bags by 10
            Medium = +Integer
    
    IF Bags < 10
    	Divide Bags by 5
            Small = +Integer
    
    Remainder:	
    IF 15 < remainder ≤ 20
           Large = +1
    
    IF 10 < remainder ≤ 15 
            Medium = +1
            Small = +1
    
    IF 5 < remainder ≤ 10
    	Medium = +1
    
    IF 1 ≤ remainder ≤ 5
    	Small = +1
    
    IF remainder = 0
    	Go to Finish
    
    Finish: 	Print	Boxes: Large, Medium, Small
    	        Print 	Cost: (Bags * 5.50) + (Large * 2.00) + (Medium * 1.00) + (Small * 0.50)
    Last edited by roman55; 02-02-2010 at 08:27 AM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    alienkinetics's Avatar
    alienkinetics is offline Programmer
    Join Date
    Feb 2010
    Location
    Australia
    Posts
    154
    Rep Power
    0

    Re: Pseudocode

    mmm. i think I did one of these back in university. I personally hate Pseudocode, because I think in the language Im coding in.

    The problem with pseudocode is, it is pushed on student because teachers beleive that most bugs are caused by lack of knowledge of a language, hence, they get you to write logic in a fake code. ie: "pseudo" "code".

    Which is kinda BS if you ask me since you cant test as you code, and you end up with a pile of usless scribbles that is good for no one. The power of coding is that you can test pieces of your code as your write. If you look at the code below, its very different (and shorter) than your pseudo code.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    float PrintCost(char* name, int quanty, float cost)
    {
      float total = quanty * cost;
      printf("%-16s %5d @ $%8.2f = $%8.2f\n", name, quanty, cost, total);
      return total;
    }
    
    int main(int argc, char* argv[])
    {
      char s[100];
      float total = 0.0;
      int lrg, med, sma, bag, i;
    
      printf("Enter Bag Count: ");
    
      i = bag = atoi(gets(s));
    
      lrg = i / 20, i -= lrg * 20;
      med = i / 10; i -= med * 10;
      sma = i /  5; i -= sma *  5;
    
      total += PrintCost("Coffee"     , bag, 5.50);
      total += PrintCost("Large Boxs" , lrg, 2.00);
      total += PrintCost("Medium Boxs", med, 1.00);
      total += PrintCost("Small Boxs" , sma, 0.50);
      puts("=================================================");
      PrintCost("TOTAL" , 1 , total);
      gets(s);
      return 0;
    }
    That said, I alwayed wrote my C code first, and then went back and wrote the pseudo code after just to please the teachers.

    Grrrrrr

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need help for Pseudocode
    By YoganRaj in forum General Programming
    Replies: 1
    Last Post: 09-28-2011, 12:10 PM
  2. Need help with pseudocode please
    By nomss in forum General Programming
    Replies: 3
    Last Post: 05-17-2011, 11:24 AM
  3. Pseudocode to C help
    By fengstar in forum C and C++
    Replies: 8
    Last Post: 04-22-2011, 06:41 AM
  4. need help with pseudocode
    By Peaches in forum General Programming
    Replies: 0
    Last Post: 05-19-2010, 05:51 AM
  5. Does anyone actually use pseudocode?
    By relapse in forum General Programming
    Replies: 26
    Last Post: 08-28-2009, 06:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts