URGENT Pseudocode help!!!

This is a discussion on URGENT Pseudocode help!!! within the C Programming forums, part of the General Programming Boards category; Hi, I have an assignment to do and my Pseudocode has to be in by tomorrow (its currently 10.30pm in ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    19

    Pseudocode help!!!

    Hi, I have an assignment to do and my Pseudocode has to be in by tomorrow (its currently 10.30pm in Ireland). The assignment is described here:
    http://www.comp.dit.ie/mcollins/ft22...signment1.html

    I just want to know if I'm doing my Pseudocode correctly. Am I supposed to put things like:
    pound = 0.70 * amount

    in my pseudocode?

    Anyway here is the first 3 cases so you can tell me if its OK.

    Code:
    BEGIN
       DO
          DISPLAY Menu of countries
          INPUT country
          SWITCH country
            
    	CASE 1
    	  DISPLAY coversion options
    	  INPUT option
    	  IF option is 1
    	    prompt for amount
    	    INPUT amount
    	    convert currency
    	    DISPLAY converted currency
    	  ELSE IF option is 2
    	    prompt for amount
    	    INPUT amount
    	    convert currency
    	    DISPLAY converted currency
    	  ELSE
    	    DISPLAY error message
    	BREAK
    	
    	CASE 2
    	  DISPLAY coversion options
    	  INPUT option
    	  IF option is 1
    	    prompt for amount
    	    INPUT amount
    	    convert currency
    	    DISPLAY converted currency
    	  ELSE IF option is 2
    	    prompt for amount
    	    INPUT amount
    	    convert currency
    	    DISPLAY converted currency
    	  ELSE
    	    DISPLAY error message
    	BREAK
    	
    	CASE 3
    	  DISPLAY coversion options
    	  INPUT option
    	  IF option is 1
    	    prompt for amount
    	    INPUT amount
    	    convert currency
    	    DISPLAY converted currency
    	  ELSE IF option is 2
    	    prompt for amount
    	    INPUT amount
    	    convert currency
    	    DISPLAY converted currency
    	  ELSE
    	    DISPLAY error message
    I'd really appreciate any help to save me staying up all night.

    Thanks a lot in advance.
    Last edited by mcgeady; 11-17-2004 at 03:53 PM.

  2. #2
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477
    Hello,

    Don't flag your question as "Urgent", even if it is for you. Claiming urgency is very likely to be counter-productive.

    All in all, your first three cases seem fine. I'm not sure where the DO stops, guessing it will be a DO-WHILE loop. Plus your BEGIN does not END, or third CASE does not BREAK, though I'm guessing it wasn't stated also.


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Nice of you to leave it to the last minute though....

    So what exactly is the difference between case 1 and case 2 ?
    Looks a lot like it needs to be a function with a parameter or two.

  4. #4
    Registered User
    Join Date
    Nov 2004
    Posts
    19
    Quote Originally Posted by Stack Overflow
    Don't flag your question as "Urgent", even if it is for you. Claiming urgency is very likely to be counter-productive.
    Edited.

    All in all, your first three cases seem fine. I'm not sure where the DO stops, guessing it will be a DO-WHILE loop. Plus your BEGIN does not END, or third CASE does not BREAK, though I'm guessing it wasn't stated also.
    I only pasted a section of the pseudocode which is why there is no end.

    So what exactly is the difference between case 1 and case 2 ?
    Thats one of the main questions I need answered. Is it OK for the first 3 cases to be identical or should I add something to change it? Case 1 is Britain (pound), case 2 is Denmark (Krone) and case 3 is Japan (Yen).

    The only thing in the code that would make case 1 different to case 2 is the wording inside the printf tags aswell as the line: "pound = 0.70 * amount" would be changed to convert from Krone to Euro and vice versa.
    Last edited by mcgeady; 11-17-2004 at 04:01 PM.

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Thats one of the main questions I need answered. Is it OK for the first 3 cases to be identical or should I add something to change it? Case 1 is Britain (pound), case 2 is Denmark (Krone) and case 3 is Japan (Yen).
    Of course it's not okay. use something like

    Code:
    CASE POUND
    Remember however, that there are no hard and fast rules for pseudo-code. The purpose of it is like sketching before painting a mural. You want to know exactly what you have where, how it's organized, and how you're going to go about painting the whole thing. It is through this that you can derive some rules requiring clarification, such as in your switch / case.

  6. #6
    Registered User
    Join Date
    Nov 2004
    Posts
    19
    So would the following be OK (changes in bold):
    Code:
    CASE POUND
    	  DISPLAY coversion options
    	  INPUT option
    	  IF option is euro to pound
    	    prompt for amount
    	    INPUT amount
    	    convert currency
    	    DISPLAY converted currency
    	  [/b]ELSE IF option is pound to euro[/b]
    	    prompt for amount
    	    INPUT amount
    	    convert currency
    	    DISPLAY converted currency
    	  ELSE
    	    DISPLAY error message
    	BREAK
    Also, one question that hasn't been answered. Should I write something like the following (instead of "convert currency"):

    Code:
    prompt for amount
    	    INPUT amount
                        pound = 0.70 * amount
    	    DISPLAY converted currency
    Thanks again.

  7. #7
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477
    The changes do look good.

    Especially now that you define what each case does.

    Quote Originally Posted by mcgeady
    Should I write something like the following (instead of "convert currency"):
    Since you did modify some of the statements in your pseudocode, it may actually be good to write the conversion process instead of "convert currency".

    Quote Originally Posted by mcgeady
    Code:
    prompt for amount
    	    INPUT amount
                        pound = 0.70 * amount
    	    DISPLAY converted currency
    Something like this looks fine. It will help define which case does what with which currency, if that makes sense.


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  8. #8
    Registered User
    Join Date
    Nov 2004
    Posts
    19
    Ok, thanks a lot. I'll check this topic in the morning for replies so if anyone has anything to add please do.

  9. #9
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    I always prefer to write my programs as scalable as possible. Something like:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    struct
    {
      char *name;            // Name of currency
      float convert_factor;  // Percent of dollar worth
    } moneys[] =
    {
      { "dollar", 1.00f },
      { "zoola",  0.32f },
      { "barwi",  1.94f },
      { "warmo",  0.86f },
      { NULL }
    };
    
    int main(void)
    {
      int choice, from, to;
      float amount;
      char buf[50];
    
      do
      {
        puts("Convert money from:");
        for(from = 0;moneys[from].name;from++)
          printf("\t%d) %s\n", from+1, moneys[from].name);
        printf("Which one (1-%d)? ", from);
        fflush(stdout);
        fgets(buf, sizeof(buf), stdin);
        choice = atoi(buf);
      } while(choice < 1 || choice > from);
    
      from = choice-1;
    
      do
      {
        puts("Convert money to:");
        for(to = 0;moneys[to].name;to++)
          if(to != from)
            printf("\t%d) %s\n", to+1, moneys[to].name);
        printf("Which one (%d-%d)? ", from == 0?2:1, (to == from+1)?to-1:to);
        fflush(stdout);
        fgets(buf, sizeof(buf), stdin);
        choice = atoi(buf);
      } while(choice < 1 || choice > to || choice == from+1);
    
      to = choice-1;
    
      printf("Amount? ");
      fflush(stdout);
      fgets(buf, sizeof(buf), stdin);
      amount = atof(buf);
    
      printf("%s: %f\n", moneys[from].name, amount);
      amount /= moneys[from].convert_factor;
      amount *= moneys[to].convert_factor;
      printf("%s: %f\n", moneys[to].name, amount);
    
      return 0;
    }
    To add another type of currency it's a matter of adding 1 simple line to the program.
    If you understand what you're doing, you're not learning anything.

  10. #10
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by itsme86
    I always prefer to write my programs as scalable as possible.
    Me too.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  11. #11
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Quote Originally Posted by Dave_Sinkula
    Heh! I hadn't seen that
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. confused n need urgent troubleshooting on C++ program
    By tezr87 in forum C++ Programming
    Replies: 2
    Last Post: 06-01-2006, 04:38 AM
  2. Linked List Need Help Urgent
    By ykchua in forum C Programming
    Replies: 5
    Last Post: 08-17-2004, 02:57 PM
  3. help... urgent,... thanks!
    By weihann in forum C Programming
    Replies: 6
    Last Post: 02-28-2002, 09:17 PM
  4. Poll: Is pseudocode really needed ?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 29
    Last Post: 02-28-2002, 05:33 PM
  5. Help.... Urgent... Thanks!
    By weihann in forum C Programming
    Replies: 0
    Last Post: 02-27-2002, 09:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21