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.
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.
That said, I alwayed wrote my C code first, and then went back and wrote the pseudo code after just to please the teachers.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; }
Grrrrrr
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks