Thread: i need a help in a little program

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    72

    Unhappy i need a help in a little program

    this program is supposed to receive an integer between 0 and 100
    and if the integer less than 5 it print a sentence
    and if it's bigger than 5 it prints another sentence
    here is the code
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    main()
    {
        int a;
        printf("could you enter an integer from one to hundread:\n");
        scanf("%d",a);
        if( a>100 || a<0)
        {
            printf("I said enter an intger between 0 and 100\n");
            scanf("%d",a);
        }
        if ( a<=0 && a>=00)          
        {
           if ( a>5)
           {
                printf(" you're much more stupid than i thought");
                getchar();
                }
           else 
           { 
                printf(" congratulation you're so stupid");
                getchar();
                }
                }
                return 0;
                }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > if ( a<=0 && a>=00)
    In other words, a == 0

    > scanf("%d",a);
    You forgot to pass the address, as in
    scanf("%d", &a);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Learn how to indent your code properly. This is how your code would look after proper indentation

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
        int a;
        
        printf("could you enter an integer from one to hundread:\n");
        scanf("%d",&a);
        
        if( a>100 || a<0)
        {
            printf("I said enter an intger between 0 and 100\n");
            scanf("%d",&a);
        }
        
        if ( a<=0 && a>=00)  /* check here for a >= 0 and a <= 100 */        
        {
           if ( a > 5)
           {
                printf(" you're much more stupid than i thought");
                getchar();
           }
           else 
           { 
                printf(" congratulation you're so stupid");
                getchar();
           }
        }
        
        return 0;
    }

  4. #4
    Registered User
    Join Date
    Jan 2007
    Posts
    72
    thanks this is the code
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
        int a;
        
        printf("could you enter an integer from one to hundread:\n");
        scanf("%d",&a);
        
        if( a>100 || a<0)
        {
            printf("I said enter an intger between 0 and 100\n");
            scanf("%d",&a);
        }
        
        if ( a >= 0 && a <= 100  /* check here for a >= 0 and a <= 100 */        
        {
           if ( a > 5)
           {
                printf(" you're much more stupid than i thought");
                getchar();
           }
           else 
           { 
                printf(" congratulation you're so stupid");
                getchar();
           }
        }
        
        return 0;
    }
    but it still cannot run what should i do ?

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
        int a;
        
        printf("could you enter an integer from one to hundread:\n");
        scanf("%d",&a);
        
        if( a>100 || a<0)
        {
            printf("I said enter an intger between 0 and 100\n");
            scanf("%d",&a);
        }
        
        if ( a>=0 && a<=100)  /* check here for a >= 0 and a <= 100 */        
        {
           if ( a > 5)
           {
                printf(" you're much more stupid than i thought");
                getchar();
           }
           else 
           { 
                printf(" congratulation you're so stupid");
                getchar();
           }
        }
        getchar();
        return 0;
    }
    
    /* my output
    could you enter an integer from one to hundread:
    5
     congratulation you're so stupid
    
    could you enter an integer from one to hundread:
    10
     you're much more stupid than i thought
    */
    Whats not working. It's working fine for me.

    ssharish2005

  6. #6
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Code:
    if ( a >= 0 && a <= 100
    Here's the error. Correction bolded:
    Code:
    if ( a >= 0 && a <= 100  )
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM