Thread: help with a simple program

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Do not ever use goto. Use a loop instead or some other conditional statement to return to that point of the code.
    Do not use getch() it's non-standard and not globally supported on all platforms. Use getchar() instead.
    Double Helix STL

  2. #2
    Registered User
    Join Date
    Jan 2017
    Posts
    12
    I see. Replaced goto with continue and getch() with getchar().

    Code:
        do
        {
            printf("\nChoose a number: \n");
            scanf("%d",&choice);
            if(choice != 1 && choice != 2 && choice != 3 && choice != 4 && choice != 5)
            {
                printf("The number you entered doesn't exist. Try again.\n");
              continue; // instead of goto
            }
                for(i=0;i<len;i++)
                {
                    if(nums[i]==choice)
                    {
                        for(j=i;j<len;j++)
                        nums[j]=nums[j+1];
                        len--;
                    }
                }
                    printf("\nNumbers left:");
                        for(i=0;i<len;i++)
                        {
                            printf(" %d",nums[i]);
                        }
            }
            while(len!=0);
            printf(" none\n");
            getchar(); // instead of getch();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple program, simple problem
    By KAUFMANN in forum C Programming
    Replies: 5
    Last Post: 02-16-2011, 01:16 PM
  2. simple program, simple error? HELP!
    By colonelhogan44 in forum C Programming
    Replies: 4
    Last Post: 03-21-2009, 11:21 AM
  3. Simple program...simple problem?
    By deadherorising in forum C Programming
    Replies: 2
    Last Post: 03-12-2009, 08:37 PM
  4. Simple program, not so simple problem
    By nolsen in forum C++ Programming
    Replies: 2
    Last Post: 01-18-2008, 10:28 AM
  5. Need help with simple, simple program.
    By LightsOut06 in forum C Programming
    Replies: 5
    Last Post: 09-01-2005, 08:31 PM

Tags for this Thread