Creation of Menu problem

This is a discussion on Creation of Menu problem within the C Programming forums, part of the General Programming Boards category; I am creating a menu program to allow the user to do currency conversions. They will be able to decide ...

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

    Creation of Menu problem

    I am creating a menu program to allow the user to do currency conversions. They will be able to decide which the original currency is and what it will be converted to. I am working on getting the text portion to work first. This is what I have so far:

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>

    /* This program will allow the user to select a country's curency and find
    what the equivalent is in another. These calculations are based on the
    values posted on the www.x-rates.com web site on Thursday, November 18,
    2004. The site had these two items as disclaimers:
    1) "The given values on this site are gathered from the Federal Reserve
    Bank of New York, representing the 12 noon buying rates and the
    floaternational Monetary Fund, according to their availability.
    2) Values and dates are believed to be reliable but this site makes no
    warranties regarding these values, fitness for a particular purpose,
    accuracy or availability."

    */
    main()
    {
    char Menu_Opt[3]; /* Menu Option */
    float Org_Curr_Amt; /* Original Currency Amount */
    float New_Curr_Amt; /* New Currency Amount */
    char Currency_Desc[24][100] = {"American Dollar (USD)", "Australian Dollar (AUD)",
    "Brazilian Real (BRL)", "British Pound (GBP)", "Canadian Dollar (CAD)",
    "Chinese Yuan (CNY)", "Danish Krone (DKK)", "Euro (EUR)", "Hong Kong Dollar (HKD)",
    "Indian Rupee (INR)", "Japanese Yen (JPY)", "Malaysian Ringgit (MYR)",
    "Mexican Peso (MXN)", "New Zealand Dollar (NZD)", "Norwegian Kroner (NOK)",
    "Singapore Dollar (SGD)", "South African Rand (ZAR)", "South Korean Won (KRW)",
    "Sri Lanka Rupee (LKR)", "Swedish Krona (SEK)", "Swiss Franc (CHF)",
    "Taiwan Dollar (TVD)", "Thai Baht (THB)", "Venezuelan Bolivar (YEB)"};
    /* Descriptions of each of the currency types that can be converted */

    printf("Currency Conversion\n");
    printf("United States Dollars Conversion Menu\n\n");
    printf("A01. USD to AUD\n");
    printf("A02. USD to BRL Y02. Transfer to AUD Conversion Menu\n");
    printf("A03. USD to GBP Y03. Transfer to BRL Conversion Menu\n");
    printf("A04. USD to CAD Y04. Transfer to GBP Conversion Menu\n");
    printf("A05. USD to CNY Y05. Transfer to CAD Conversion Menu\n");
    printf("A06. USD to DKK Y06. Transfer to CNY Conversion Menu\n");
    printf("A07. USD to EUR Y07. Transfer to DKK Conversion Menu\n");
    printf("A08. USD to HKD Y08. Transfer to EUR Conversion Menu\n");
    printf("A09. USD to INR Y09. Transfer to HKD Conversion Menu\n");
    printf("A10. USD to JPY Y10. Transfer to INR Conversion Menu\n");
    printf("A11. USD to MYR Y11. Transfer to JPY Conversion Menu\n");
    printf("A12. USD to MXN Y12. Transfer to MYR Conversion Menu\n");
    printf("A13. USD to NZD Y13. Transfer to MXN Conversion Menu\n");
    printf("A14. USD to NOK Y14. Transfer to NZD Conversion Menu\n");
    printf("A15. USD to SGD Y15. Transfer to NOK Conversion Menu\n");
    printf("A16. USD to ZAR Y16. Transfer to SGD Conversion Menu\n");
    printf("A17. USD to KRW Y17. Transfer to ZAR Conversion Menu\n");
    printf("A18. USD to LKR Y18. Transfer to KRW Conversion Menu\n");
    printf("A19. USD to SEK Y19. Transfer to LKR Conversion Menu\n");
    printf("A20. USD to CHF Y20. Transfer to SEK Conversion Menu\n");
    printf("A21. USD to TVD Y21. Transfer to CHF Conversion Menu\n");
    printf("A22. USD to THB Y22. Transfer to TVD Conversion Menu\n");
    printf("A23. USD to YEB Y23. Transfer to THB Conversion Menu\n");
    printf(" Y24. Transfer to YEB Conversion Menu\n\n");
    printf("Y99. Exit Program\n");
    printf("Option: ");
    scanf("%c", Menu_Opt);

    if(Menu_Opt == "A01")
    {
    printf("\nPlease enter your value of %s\n", Currency_Desc[0]);
    printf("\nYour Equivalent %s", Currency_Desc[1]);
    printf(" is \n");
    }
    if(Menu_Opt == "A02")
    {
    printf("\nPlease enter your value of %s\n", Currency_Desc[0]);
    printf("\nYour Equivalent %s", Currency_Desc[2]);
    printf(" is\n");
    }
    )

    When I run the program, I do not get the next lines to print and the program exits. Is there something wrong with my "If" logic, or what is wrong? Any help would be greatly appreciated.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,171
    Menu_Opt is an array but you're doing scanf("%c", Menu_Opt); Also, you're going to need to make Menu_Opt 4 elements wide to hold a 3-letter string because you need to make room for the null-terminating zero.

    Another thing is you can't compare strings using the == operator (well you can, but not in the way you're trying to here.) Look at the strcmp() function.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    41

    Creation of Menu problem

    I don't want to sound stupid, but can you please show me how to use the strcmp command?

  4. #4
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    put your code in code tags. then read here then read here

    Another thing is you can't compare strings using the == operator (well you can, but not in the way you're trying to here.) Look at the strcmp() function.
    let's be real you can't compare strings with the == operator you can compare their addresses.

  5. #5

  6. #6
    Registered User
    Join Date
    Nov 2004
    Posts
    41
    Thank you for your help. I got it working now!!!!

  7. #7
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Quote Originally Posted by caroundw5h
    let's be real you can't compare strings with the == operator you can compare their addresses.
    C++...

    You can also use stricmp() to compare strings ignoring case. It's used the same way as strcmp().

  8. #8
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by xErath
    C++...

    You can also use stricmp() to compare strings ignoring case. It's used the same way as strcmp().
    what forum is this again?

  9. #9
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477
    Quote Originally Posted by xErath
    C++...

    You can also use stricmp() to compare strings ignoring case. It's used the same way as strcmp().
    Keep in mind this function is a common extension on many C compilers and is not part of either C or C++ standards. Many compilers support this function, but it's an addon, or compiler specific function.

    If you are looking for a reference or code example of this function, you can always check this out: stricmp source


    - 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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu problem.
    By And3rs in forum C++ Programming
    Replies: 25
    Last Post: 10-12-2008, 11:48 AM
  2. Case: Problem...
    By Jst in forum C Programming
    Replies: 7
    Last Post: 04-24-2005, 08:07 AM
  3. MDI and MENU Problem
    By Marc in forum Windows Programming
    Replies: 3
    Last Post: 02-21-2004, 06:59 PM
  4. overlay creation problem
    By kiss_psycho in forum C Programming
    Replies: 0
    Last Post: 12-26-2003, 02:59 PM

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