Like Tree1Likes
  • 1 Post By claudiu

Write a program which will display the following menu: 1. Display Grocery List 2. Mo

This is a discussion on Write a program which will display the following menu: 1. Display Grocery List 2. Mo within the C Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> #incude<conio.h> main() { char sel,sels,selss,selsss; int sub=0,n=0,total=0; printf("\n 1. Grocery List \n 2. Modify Grocery List \n 3. ...

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    7

    Post Write a program which will display the following menu: 1. Display Grocery List 2. Mo

    Code:
    #include<stdio.h>
    #incude<conio.h>
    main()
    {                    
        char sel,sels,selss,selsss;
        int sub=0,n=0,total=0;
        printf("\n 1. Grocery List \n 2. Modify Grocery List \n 3. Total");
        scanf("%c",&sel);
        if(sel=='1')
        {
            printf("\n1. Cake \n2. Rice \n3. Sugar \n4. Liquor \n5. Weed \n6. Smoke \n7. Total \n");
            scanf("%c", &sels);
            do
            {
                if(sels=='1')     sub=sub+10;
                
                else if(sels=='2')    sub=sub+20;
                
                else if(sels=='3')    sub=sub+20;
    
                else if(sels=='4')    sub=sub+40;
    
                else if(sels=='5')    sub=sub+100;
    
                else if(sels=='6')    sub=sub+100;
    
                else if(sels=='7')
                {
                    printf("\n Thank You :-)  ");
                    total=sub;
                    n=1;
                }
            }while(n==0);
    
        }
        else if(sel=='2')
        {
            printf("\n 1. Add Item \n 2. Drop Item");
            scanf("%c",&selss);
            if(selss=='1')
            {
                printf("\n Select the Item to Add");
                printf("\n1. Cake \n2. Rice \n3. Sugar \n4. Liquor \n5. Weed \n6. Smoke \n7. Total \n");
                scanf("%c", &sels);
                do
                {
                    if(sels=='1')     sub=sub+10;
                
                    else if(sels=='2')    sub=sub+20;
                    
                    else if(sels=='3')    sub=sub+20;
    
                    else if(sels=='4')    sub=sub+40;
    
                    else if(sels=='5')    sub=sub+100;
    
                    else if(sels=='6')    sub=sub+100;
            
                    else if(sels=='7')
                    {
                        printf("\n Thank You :-)  ");
                        total=sub;
                        n=1;
                    }
                }while(n==0);
            else if(selss=='2')
            {
                printf("\n Select the Item to Drop");
                printf("\n1. Cake \n2. Rice \n3. Sugar \n4. Liquor \n5. Weed \n6. Smoke \n7. Total \n");
                scanf("%c", &sels);
                do
                {
                    if(sels=='1')     sub=sub-10;
                    
                    else if(sels=='2')    sub=sub-20;
                    
                    else if(sels=='3')    sub=sub-20;    
    
                    else if(sels=='4')    sub=sub-40;
            
                    else if(sels=='5')    sub=sub-100;
        
                    else if(sels=='6')    sub=sub-100;
        
                    else if(sels=='7')
                    {
                        printf("\n Thank You :-)  ");
                        total=sub;
                        n=1;    
                    }            
                }while(n==0);
            }
    
        else if(sel=='3');
        {
            printf("\n The Total is : $ %d",&total);
            printf("\n ThankYou !!! for shopping here :] ");
        }
    }

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    7
    Can anybody please help me with this thing The whole question is as follows
    Write a program which will display the following menu:

    1. Display Grocery List
    2. Modify Grocery List
    3. Calculate Total (including taxes)


    Write the rest of the program so that the list can take up to any 5 items.

  3. #3
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    What exactly is the problem? (besides the fact that you need to stop using compilers from another century)
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    7
    The problem is that when i press Grocery list it shows the list than when i press the selection it doesn't do anything and i have used bloodshed

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    7
    One more pressing edit grocery list shows add or drop item but it comes with a huge total

  6. #6
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Yes, get rid of bloodshed, which is rubbish in its purest form, get rid of conio and all the antiquated barf. Change your crazy if elses to single, clean switch statements. When you read in a character with scanf, you actually leave your return key in the buffer and read it the next time you call scanf which is probably why you don't see anything.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  7. #7
    Registered User
    Join Date
    May 2012
    Posts
    7
    Please can you list me all the problems that it is facing so that i just edit it once please it would be a huge help

  8. #8
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    If you want to just edit it once you are in the wrong profession my friend.
    QuantumPete likes this.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  9. #9
    Registered User
    Join Date
    May 2012
    Posts
    7
    I'm not in the profession just helping friend who doesn't know how to make c program just can you help me and do a favor would be really good

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    2,613
    Number one problem in my opinion, is the lack of user defined function to make the code easier to understand and maintain.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  11. #11
    Registered User
    Join Date
    May 2012
    Posts
    7
    Is there any one who can help me instead of commenting an showing my mistakes.Would be a real help if you use your knowledge and help someone.

  12. #12
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Read the forum guidelines for homework. We help people do their homework, we don't do it for them.

    I have already provided you with a list of things that need to be changed.

    Announcements - General Programming Boards
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  13. #13
    Registered User
    Join Date
    May 2009
    Posts
    2,613
    Code:
        char sel,sels,selss,selsss;
        int sub=0,n=0,total=0;
    Where I learned the above was considered bad style.
    Should be one declared variable per line.
    And, if the meaning was not obvious, have a comment at end of the line.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  14. #14
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    You should really have a function to display/return the menu, so you don't have to copy/paste the same code over and over again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu Display Help
    By sharingan_gv in forum C Programming
    Replies: 1
    Last Post: 07-28-2011, 12:28 AM
  2. Display system menu
    By silverAG in forum Windows Programming
    Replies: 1
    Last Post: 02-17-2009, 09:42 PM
  3. Display a hex value in a list box?
    By klipseracer in forum Windows Programming
    Replies: 5
    Last Post: 01-27-2008, 09:46 AM
  4. Nested for loop...search & display a list within a list
    By chadsxe in forum C++ Programming
    Replies: 13
    Last Post: 07-20-2005, 01:34 PM
  5. Display list not displaying?
    By psychopath in forum Game Programming
    Replies: 5
    Last Post: 09-19-2004, 06:47 PM

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