Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Beginner c program - Getting error

  • 23-10-2011 09:12PM
    #1
    Registered Users, Registered Users 2 Posts: 1,995 ✭✭✭


    Hi,
    I'm using Code::Blocks as my IDE and gcc is being used as the compiler I think.

    When I try to run the below code I get a process returned 320 error. Can anyone tell me what the problem is? I'm using Kernighan & Ritchies book and am trying to apply knowledge I've learned so far.

    I think it may be to do with the last line as changes to this affect whether the program will run or not (if it does run after changing value = lower + step it repeatedly throws out 20. The IDE also shows this error. Process terminated with status -1073741510 (0 minutes, 4 seconds)

    Also can anyone tell me how I can add proper code formatting into posts on boards?

    Thanks a mill.

    #include <stdio.h>

    main()
    {
    int value;
    int lower, upper, step;

    lower = 0;
    upper = 300;
    step = 20;

    value = lower;
    while (value <= upper) {
    printf("%d", value);

    value = value + step;
    }
    }


Comments

  • Registered Users, Registered Users 2 Posts: 1,346 ✭✭✭carveone


    For code formatting press the # button or wrap it in CODE tags.

    I don't see it, whatever is wrong. The return value is garbage because you should really have a

    return 0;

    at the end and main should be
    int main() {..}

    but I don't see any other issue.

    By the way you do say "value = lower + step" in your comment (which would print 20 all the time) but the code says "value = value + step" which appears right.

    Edit: I don't think anything is wrong. Code Blocks is probably just reporting what it thinks your program returned. If you return 0, it'll probably say "process returned: 0"


  • Registered Users, Registered Users 2 Posts: 1,456 ✭✭✭FSL


    You are not incrementing step.

    You seem to want to go through a loop but you are not looping.

    Always represent your programme graphically before coding, that way you stand half a chance of getting it right.


  • Registered Users, Registered Users 2 Posts: 221 ✭✭Elfman


    FSL wrote: »
    You are not incrementing step.

    You seem to want to go through a loop but you are not looping.

    Always represent your programme graphically before coding, that way you stand half a chance of getting it right.



    The Loop is checking for Value which is being incremented by the value of step.
    no need to increment step.

    I'd try the return 0; and see if that helps


  • Registered Users, Registered Users 2 Posts: 1,995 ✭✭✭euser1984


    FSL wrote: »
    You are not incrementing step.

    You seem to want to go through a loop but you are not looping.

    Always represent your programme graphically before coding, that way you stand half a chance of getting it right.

    Can you let me know what you mean here?
    Elfman wrote: »
    The Loop is checking for Value which is being incremented by the value of step.
    no need to increment step.

    I'd try the return 0; and see if that helps

    I've got it working now. To move the value up do I not need to increase it using the step value of 20. Otherwise the value will always be the same?


Advertisement