Thread: Hello all im new around here.

  1. #1
    Registered User
    Join Date
    Dec 2015
    Location
    Uk
    Posts
    5

    Hello all im new around here.

    Hello all,

    So first a little bit about my problem. I've recently been studying C and programming in general. My maths background is pretty poor and I didn't take too well to it in school. So I always avoided programming up till now. I have been lurking on programming forums and Reddit for a while and watched quite a few tutorials and attempted to write basic strings of code e.g "Hello, world" etc.. Sooo my problem is I have now completely hit a brick wall, I started following a Computer Science course on Github provided by the OSS university.

    https://github.com/open-source-socie...an-oss-student

    Everything was going fine and I have been taking notes constantly, which i can look back on and understand.
    I completed the first week in the CS50 course then the second jumped to a problem set that i can not get my head around. I have looked at quite a few explanations of Nested loops, Do while loops and while loops, but when it comes to construct one for a problem like this:https://youtu.be/z32BxNe2Sfc I just can't seem to get my head round it at all and even writing the psudocode for it just won't go in.

    I'm not asking for anyone to tell me exactly what to do. Just a few explanations of how to contemplate this type of function. I also understand if you think this post is a complete waste of time and don't want to help, feel free to ignore.
    Any help will be much appreciated and I will keep researching in the meantime as much as I can.

    Here is the start of my code:
    https://github.com/ashzor1337/test/blob/master/pset1.c

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,127
    Quote Originally Posted by ba'alzamon View Post
    Hello all,

    So first a little bit about my problem. I've recently been studying C and programming in general. My maths background is pretty poor and I didn't take too well to it in school. So I always avoided programming up till now. I have been lurking on programming forums and Reddit for a while and watched quite a few tutorials and attempted to write basic strings of code e.g "Hello, world" etc.. Sooo my problem is I have now completely hit a brick wall, I started following a Computer Science course on Github provided by the OSS university.

    https://github.com/open-source-socie...an-oss-student

    Everything was going fine and I have been taking notes constantly, which i can look back on and understand.
    I completed the first week in the CS50 course then the second jumped to a problem set that i can not get my head around. I have looked at quite a few explanations of Nested loops, Do while loops and while loops, but when it comes to construct one for a problem like this:https://youtu.be/z32BxNe2Sfc I just can't seem to get my head round it at all and even writing the psudocode for it just won't go in.

    I'm not asking for anyone to tell me exactly what to do. Just a few explanations of how to contemplate this type of function. I also understand if you think this post is a complete waste of time and don't want to help, feel free to ignore.
    Any help will be much appreciated and I will keep researching in the meantime as much as I can.

    Here is the start of my code:
    https://github.com/ashzor1337/test/blob/master/pset1.c
    You should post your code here in Code tags, "[CODE]", and "[\CODE]", without the quotes!

    "GetInt()" is not a Standard Library function, I have never seen or used it, so I can't comment on it's use.

    Code:
     while (v > 0 && v <=23);
    This will check for a number between 1 and 23, not 0 and 23! Did you mean:
    Code:
     while (v >= 0 && v <=23);

  3. #3
    Registered User
    Join Date
    Dec 2015
    Location
    Uk
    Posts
    5
    Thank you for the feedback. I will bare that in mind! Yes I did mean between 0 & 23. GetInt was a libary function created by the CS50 course. This is what the linux manual tells me "GetInt - Read a line from standard input and return the equivalent int."

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Welcome to the forum. And nice user-name

    I don't know anything about the CS course you describe - but regarding the youtube link, I usually discourage video for purposes of learning a programming language. Instead I recommend getting a book. Even tutorials are weak compared to a good book.

    Also, you should explain the problem you're having and post the relevant code here, using code tags.

    You should have a compiler set up on your computer. Do you have one? And if so, which?

    A compiler should generate warnings and errors if there are problems with your code. In the future, if your code fails to compile and you don't know why, also post the errors here so we can help you fix them.



    Let's look at the do-while loop, since that's what you linked.

    Code:
    do
    {
        /* code to repeat */
    } while ( /* true */ );
    Notice that the code you want to repeat goes after the "do". The braces are optional if there is only one statement - for multiple statements, they need to be enclosed in braces (to create a "block").

    This is a piece from what you linked:

    Code:
    do printf("please give me a value between 0-23:\n"); 
            }
            v =GetInt();
            {
            while (v > 0 && v <=23);
    Problems:

    1. You have a statement directly after the "do" but before the opening brace of the following block of code
    2. You have an closing brace where the opening brace should be.
    3. "GetInt()" is not a standard function (as rstanley already mentioned).
    4. You have an opening brace where the closing brace should be.

    The loop will continue from the start if the expression after the "while()" evaluates to true. Otherwise, the loop stops and program execution continues from that point.

  5. #5
    Registered User
    Join Date
    Dec 2015
    Location
    Uk
    Posts
    5
    Code:
    #include <cs50.h> #include <stdio.h> int main(void) { int v; /// ask for user input, then validate./// do printf("please give me a value between 0-23:\n"); } v =GetInt(); { while (v= > 0 && v <=23); }

  6. #6
    Registered User
    Join Date
    Dec 2015
    Location
    Uk
    Posts
    5
    Thanks again for the response. All this is really helpful information and do you have any recommendations to a good book to start with in C.
    I will pick apart my code tonight and repost any compiler errors I encounter.
    I'm currently using a compiler the course provided. It's also integrated with gedit.

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    There is a C book recommendation thread sticked in the main C forum.

  8. #8
    Registered User
    Join Date
    Dec 2015
    Location
    Uk
    Posts
    5
    Code:
    #include<cs50.h>
    #include<stdio.h>
    
    int main(void)
    {
    
    
    int i = 0;
    do{
        while(i == 0)
            {
    printf("Please enter a Value between 0 and 23:\n");
    scanf("%i", &i);
            }
    
    while (i < 0 || i > 23);
    
    printf("enter a new value, your input is incorrect");
            {
    while (i >= 0 || i <= 23);   
    
    printf("#");
            }
      }
    Just an update if anyone is interested so far. Still getting two errors at the moment, will just keep working on it.

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    What are the errors?

    What is the purpose of those empty bodied while loops?

    A little saner indentation style will go a long way towards making your code readable.

    Code:
    #include<cs50.h>
    #include<stdio.h>
    
    int main(void)
    {
    
    
        int i = 0;
        do {
            while(i == 0)
            {
                printf("Please enter a Value between 0 and 23:\n");
                scanf("%i", &i);
            }
    
            while (i < 0 || i > 23);
    
            printf("enter a new value, your input is incorrect");
            {
                while (i >= 0 || i <= 23);
    
                printf("#");
            }
        }
    Where is your closing brace for main()?

    Jim

Popular pages Recent additions subscribe to a feed

Tags for this Thread