Please Help A Noob Here (plz Im Begging You)

This is a discussion on Please Help A Noob Here (plz Im Begging You) within the C Programming forums, part of the General Programming Boards category; Read your code. Each and every line and understand exactly what it does. Then write a flowchart with that, knowing ...

  1. #46
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    Read your code. Each and every line and understand exactly what it does.
    Then write a flowchart with that, knowing what it does.
    Then insert your check where appropriate in the flowchart.
    Then translate it to code.

    It will do you wonders.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #47
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    varts what can i say you are a legend
    so the real devils are { and }
    thx for the help mats and elysia
    since im on it
    im just wondering how do i convert year outputs into words?
    does it involve with enumerations cause if it does dont i have to create some sort of dictionary?
    any pointers plz?

  3. #48
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You will need some sort of translation of number to string - if you want to call that a dictionary, then that's probably closer than an "enumeration".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #49
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by vart View Post
    see my sample
    that's not a sample, that's the answer :P

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  5. #50
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    translation of number to string....
    right....
    are there websites or tutorials that can tell me about that cause i have no idea how to start at all
    thx mats

    P.s: does it invole #include <stdlib.h>??? there's only one setence from this website (http://www.cs.cf.ac.uk/Dave/C/node16...00000000000000)
    which does not really help

  6. #51
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    Don't worry about including headers.
    Worry about what functions to use, and when you use those functions, include appropriate header.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #52
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    haha i just need a header in case my teacher saw this thread and said i plagiaries

  8. #53
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You definitely don't need stdlib.h for this particular task:
    Code:
    #include <stdio.h>
    
    int main()
    {
      char *numbers[] = { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };
    
      int n;
    
      printf("Enter a number:");
      fflush(stdout);
      scanf("%d", &n);
      printf("Last digit of number is %s", numbers[n % 10]);
      return 0;
    }
    This solves PART of your problem - now you have to find the rest of the solution.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #54
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    Including a header without using is bad. Especially if you just want someone to "see" that header.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #55
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    thx for the sample mat
    can someone explain what is
    fflush(stdout);?
    and
    char *numbers[] ?

  11. #56
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    fflush(stdout) -> flushes output buffer, makes sure the user sees the "Enter a number:" text.
    char* numbers[] (as I like to type it) clearly shows that it's an array of pointers (type) and [] means that the dimensions are undefined (the compiler will determine this depending on what you initialize it with).

    But this should really be const char*...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #57
    abyss - deep C
    Join Date
    Oct 2007
    Posts
    46
    Quote Originally Posted by QuantumPete View Post
    that's not a sample, that's the answer :P

    QuantumPete
    Now that he's got the answer, I'd like to post my version
    Code:
    void processInput(int year, int month)
    {
        int leap = ( (year%4 == 0 && year%100 != 0) || year%400 == 0 )? 1:0;
                    // one of the ways to check if a given year is leap
                    
        int monthDays[] = {31,28+leap,31,30,31,30,31,31,30,31,30,31};
                    // adjust num of days in February accordingly
                    
        const char *monthStr[12] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
                    // string constants for each month
                    
        char yearStr[40];
                    // string variable for year in words
    
        getYearInWords(yearStr, year);
    
        printf("year %d (%s) has %d days\n", year, yearStr, (365+leap));
        printf("month %d (%s) has %d days\n", month, monthStr[month-1], monthDays[month-1]);
    }
    I've got the function
    Code:
    getYearInWords(yearStr, year);
    ready but didn't post it coz i don't want to stop him learning.
    Anyway, this function just uses logic as explained earlier by matsp

    cheers
    maverix

  13. #58
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    But if you want something fancy, you can do this
    Code:
    int leap = !!( (year &#37; 4 == 0 && year % 100 != 0) || (year % 400 == 0) );
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #59
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    But if you want something fancy, you can do this
    Code:
    int leap = !!( (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0) );
    You don't need !! for that, as it' produces a "bool" in the first place.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #60
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    You may be correct...
    I didn't really think of it.
    Last edited by Elysia; 03-27-2008 at 07:33 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 4 of 7 FirstFirst 1234567 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. The ultimate noob lol...plz help
    By thatpkrguy in forum C++ Programming
    Replies: 14
    Last Post: 11-10-2005, 05:53 PM
  3. plz help here, noob actually .D
    By BjoRn3n in forum C++ Programming
    Replies: 1
    Last Post: 03-07-2005, 02:04 PM
  4. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM
  5. noob: compiling error... plz help!
    By chosii in forum C Programming
    Replies: 2
    Last Post: 05-10-2002, 05:53 AM

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