Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 40

Thread: What is wrong with this code?

  1. #21
    Join Date
    Mar 2006
    Posts
    325
    Rep Power
    0

    Default

    Quote Originally Posted by carey View Post
    This works in my compiler but doesn't work on ideone.com: http://ideone.com/LbeTp

    Guess this compiler needs to be more strict.
    theres nothing wrong with it. you need to return 0 when youre done

    http://ideone.com/cc0G9
    1337

  2. #22
    Join Date
    Jul 2002
    Posts
    1,395
    Rep Power
    0

    Default

    Quote Originally Posted by wiel View Post
    theres nothing wrong with it. you need to return 0 when youre done

    http://ideone.com/cc0G9
    I thought return 0 was only to certify successful execution?

  3. #23
    Join Date
    Dec 2004
    Posts
    261
    Rep Power
    0

    Default

    the one i did looked like this
    #include<stdio.h>
    #include<stdlib.h> //Header Files
    #include<conio.h>


    main()
    {
    int small_Pos, large_Pos=0;
    int num=0; //Declaring & Initializing variables
    int large_Neg=-99999, small_neg;
    int total_Pos=0, total_Neg=0;

    do
    {
    printf("Welcome to the program! \n "); //Welcoming prompt
    printf("Please enter a number:"); //Prompt to user for input
    scanf("%d", &num);

    if((num > 0) && (num != 999))
    {
    total_Pos = total_Pos + num; //accumilating the total of the positve numbers

    if(num > large_Pos) //checking to see if the entered number is greater than the largest positive number
    {
    large_Pos = num;
    }
    if(num < small_Pos) //checking to see if the entered number is less than the smallest positive number
    {
    small_Pos = num;
    }
    }

    if(num < 0)
    {
    total_Neg = total_Neg + num; //accumilating the total of the positve numbers

    if(num >= large_Pos) //checking to see if the entered number is greater than or equal to the largest negative number
    {
    large_Pos = num;
    }
    if(num <small_neg) //checking to see if the entered number is less than the smallest negative number
    {
    small_neg = num;
    }
    }

    }
    while(num != 999);

    printf("The total of all the positive numbers is: %d \n" , total_Pos);
    printf("The total of all the negative numbers is: %d \n" , total_Neg);
    printf("The smallest of the positive numbers is: %d \n" , small_Pos); //Output from the program
    printf("The largest of the positive numbers is: %d \n" ,large_Pos);

    printf("The smallest negative number is: %d \n" , small_neg);
    printf("The largest negative number is: %d \n" , large_Neg);

    getch();

    }
    I am str88,no curves no bends.
    nokia rocks(iphone too)

    21.5 emachice 1080p .... intel core 2 quad q6600 ... 4gig ocz memory ....h/d 320g....gpu ati hd 5750 1gddr5..m/B..intel

  4. #24
    Join Date
    Mar 2006
    Posts
    325
    Rep Power
    0

    Default

    Quote Originally Posted by carey View Post
    I thought return 0 was only to certify successful execution?
    thats how all your programs should end.some compilers wont do it for you. other compilers either run a check or catch the error and handle it for you i guess
    1337

  5. #25
    Join Date
    Jul 2002
    Posts
    1,395
    Rep Power
    0

    Default

    Quote Originally Posted by theo View Post
    the one i did looked like this
    #include<stdio.h>
    #include<stdlib.h> //Header Files
    #include<conio.h>


    main()
    {
    int small_Pos, large_Pos=0;
    int num=0; //Declaring & Initializing variables
    int large_Neg=-99999, small_neg;
    int total_Pos=0, total_Neg=0;

    do
    {
    printf("Welcome to the program! \n "); //Welcoming prompt
    printf("Please enter a number:"); //Prompt to user for input
    scanf("%d", &num);

    if((num > 0) && (num != 999))
    {
    total_Pos = total_Pos + num; //accumilating the total of the positve numbers

    if(num > large_Pos) //checking to see if the entered number is greater than the largest positive number
    {
    large_Pos = num;
    }
    if(num < small_Pos) //checking to see if the entered number is less than the smallest positive number
    {
    small_Pos = num;
    }
    }

    if(num < 0)
    {
    total_Neg = total_Neg + num; //accumilating the total of the positve numbers

    if(num >= large_Pos) //checking to see if the entered number is greater than or equal to the largest negative number
    {
    large_Pos = num;
    }
    if(num <small_neg) //checking to see if the entered number is less than the smallest negative number
    {
    small_neg = num;
    }
    }

    }
    while(num != 999);

    printf("The total of all the positive numbers is: %d \n" , total_Pos);
    printf("The total of all the negative numbers is: %d \n" , total_Neg);
    printf("The smallest of the positive numbers is: %d \n" , small_Pos); //Output from the program
    printf("The largest of the positive numbers is: %d \n" ,large_Pos);

    printf("The smallest negative number is: %d \n" , small_neg);
    printf("The largest negative number is: %d \n" , large_Neg);

    getch();

    }
    Boreland C is your IDE? I am using Codeblocks.

  6. #26
    Join Date
    Dec 2004
    Posts
    261
    Rep Power
    0

    Default

    i use dev and borland c
    I am str88,no curves no bends.
    nokia rocks(iphone too)

    21.5 emachice 1080p .... intel core 2 quad q6600 ... 4gig ocz memory ....h/d 320g....gpu ati hd 5750 1gddr5..m/B..intel

  7. #27
    Join Date
    Jul 2002
    Posts
    1,395
    Rep Power
    0

  8. #28
    Join Date
    Jul 2002
    Posts
    1,395
    Rep Power
    0

    Default

    Taking a break from Codeblocks for awhile. Looking for something that gives more understandable feedback. Right now Pelles' C for Windows is where it's at; along with MinGW+LLVM/Clang.

    I didn't want to post this in a non-functional state. But seeing as Windows being a battyman with its "issues", here it is:
    http://ideone.com/vYKgu

    I was asking my lecturer if it would have been easier to use multiple module files. She advised against it. Now this is turning out to be one massive dish of spaghetti.

  9. #29
    Join Date
    Dec 2004
    Posts
    261
    Rep Power
    0

    Default

    i did that same course work too
    I am str88,no curves no bends.
    nokia rocks(iphone too)

    21.5 emachice 1080p .... intel core 2 quad q6600 ... 4gig ocz memory ....h/d 320g....gpu ati hd 5750 1gddr5..m/B..intel

  10. #30
    Join Date
    Jul 2002
    Posts
    1,395
    Rep Power
    0

    Default

    http://ideone.com/vvX2T

    Menu 5 is skipping the first structure array member. Why? I am going to get some sleep.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •