What is wrong with my coding? Done but something's wrong somewhere.

This is a discussion on What is wrong with my coding? Done but something's wrong somewhere. within the C Programming forums, part of the General Programming Boards category; Hey guys,can you please help me out here. Thanks. Code: #include<stdio.h> #include<string.h> int main(void) { int array[100]; int i,maxi,nvalue; /*I'm ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    5

    What is wrong with my coding? Done but something's wrong somewhere.

    Hey guys,can you please help me out here. Thanks.
    Code:
    #include<stdio.h>
    #include<string.h>
    int
    main(void)
    {
     int array[100];
     int i,maxi,nvalue;
    /*I'm trying to make system print numbers less than and equal to 100 in an array. When that is done it must ask the user for an imput(n),then
    calculate the sum of numbers in the array between –n and n inclusive.*/
    
    printf("Enter some integers here:"); 
    for (i=0;i<100;++i)
    {
    scanf("%d",&array[i]);
    
    if(array[i]==-1)
    {
    maxi = i;
    break;
    }
    maxi=100;
    }
    printf("\n%d",array);
    while(nvalue >maxi)
    {
    scanf("%d");
    printf("Please try again");
    
    /* Lets calculate the sum*/
    printf("The sum is:");
    return(0);
    } 
    }
    Attached Images Attached Images  
    Last edited by mpilot; 11-14-2011 at 03:27 PM. Reason: First post was blurry

  2. #2
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    You might consider two things:

    1. Indenting your code: SourceForge.net: Indentation - cpwiki
    2. Instead of just posting code and saying "something's wrong", you tell us what it is you are seeing that is not what you expect. All I see is a screen that is waiting for you to provide some input, which is as the code is written.

    EDIT: Oh, a third thing:

    Code:
    while(nvalue >maxi)
    nvalue is not initialized with a value, so you have no idea what it might contain when you hit this loop the first time. Actually, nvalue never appears to change, so I don't know what you're doing. And this:
    Code:
    printf("\n%d",array);
    is not how you print an array.
    Last edited by rags_to_riches; 11-14-2011 at 04:01 PM.

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    20
    where's your sum loop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wrong wrong with my xor function?
    By Anddos in forum C++ Programming
    Replies: 5
    Last Post: 04-26-2009, 01:38 PM
  2. whats wrong with this? no errors but wrong result
    By InvariantLoop in forum C Programming
    Replies: 6
    Last Post: 01-27-2005, 11:48 PM
  3. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  4. What's wrong with my coding?
    By EeeK in forum C Programming
    Replies: 28
    Last Post: 10-09-2003, 05:32 AM
  5. coding done. Two minor bugs. where did I go wrong?
    By mastering_c in forum C Programming
    Replies: 2
    Last Post: 06-25-2002, 11:21 AM

Tags for this Thread


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