Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Beginner c program - Getting error

  • 23-10-2011 8:12pm
    #1
    Registered Users, Registered Users 2 Posts: 1,977 ✭✭✭


    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,306 ✭✭✭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,977 ✭✭✭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