Thread: I need a very simple example please help

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    19

    I need a very simple example please help

    I lost my notes about this one and my classmates are really useless because they don't copy a damn simple code. My teacher said find it out and it's been my second day answering and still i cant find/solve/code it.

    so here you go guys please help me, Requirements:
    Make the user prompt 5 numbers, the 5 numbers passes through an array, then let the user prompt 1 number to be searched either its one of the 5 numbers or not. If the number is in the array it displays "Num. is in the Array", if not in array "Num. is not in the Array".

    my codes that i'm been tackling:
    Code:
    main()
    {
    int x,i,b,a[5];
    clrscr();
    g(1,1);
    p("Enter 5 Numbers: ");
    s("%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5]);
    g(1,8);
    p("Search Number: ");
    s("%d",&b);
    x=9;
    for(i=1;i<6;i++)
       {
       if(a[i]==b)
          {
          g(22,x);
          p("Number in Array");
          x++;
          }
       else
          {
          g(22,x);
          p("Number not in array");
          x++;
          }
       }
    getch();
    and i was sure that my teachers codes were 1/3 shorter than mines. when i try to run it, it also loops the "Number is in array" and " NUmber is not in array".

    So guys this is one of the basics she said, please help me...

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I don't understand the single letter on the far left side of several of your lines of code.

    Code:
    for(i = 0, i < 5; i++)               //data entry
       scanf("%d", &a[i];
    
    
    printf("\nEnter the number to be searched for: ");
    scanf("%d", &goal);
    
    for(i = 0, found = 0; i < 5; i++)  {   // 0 through 4 is 5 numbers
       if(goal == a[i])
          printf("\nNumber %d was found", goal);
    }

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    19
    btw... where will you place the "Number is not in Array" in your codes?

  4. #4
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by jazzglenn421 View Post
    codes?
    Code (as in sourcecode) has no plural. It's only teenage imbeciles that write "Giz us teh codez"...

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    19
    Quote Originally Posted by QuantumPete View Post
    Code (as in sourcecode) has no plural. It's only teenage imbeciles that write "Giz us teh codez"...

    QuantumPete
    Sorry, i'm just new to C ok?... i'm a total newbie all i know is playing online/offline games and i just took this subject cus its in my curriculum, i learned to love it and hope to be good at it. So please stay on topic.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Code:
    for(i = 0, i < 5; i++)               //data entry
       scanf("%d", &a[i];
    
    
    printf("\nEnter the number to be searched for: ");
    scanf("%d", &goal);
    
    for(i = 0, found = 0; i < 5; i++)  {   // 0 through 4 is 5 numbers
       if(goal == a[i])  {
          printf("\nNumber %d was found", goal);
          found = 1;
       }
    }
    
    if(!found)
       printf("%d was not in the array", goal);
    I'm being a "giving tree" here for you, one time. Don't expect it with such little work on your part, next time. It won't happen.

    You know you're behind the curve on this, so study up.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 05:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM