Thread: C program idea not sure!

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    3

    C program idea not sure!

    Here is an idea that I thought was pretty cool.

    I just got a book on C, never really coded anything but I want the program to do the following

    I want it to calculate the age of an actor when a specific movie was released

    For example

    Input would be

    Zodiac Signs

    Actor name = Al Pacino

    Actor Bday = 04/23/1940

    Film Name = God Father

    Film Release Date = 1972

    OUTPUT:

    When Al Pacino filmed "The Godfather" he was "32" years old, Al Pacino is currently 68 years old and is a "Taurus" The Godfather was made "36" years ago

    Can someone show me how this would work or atleast get me started. Thanks

  2. #2
    Registered User
    Join Date
    Jul 2008
    Posts
    3
    I know this is wrong but this is a basic structure I thought of

    #include <stdio.h>
    int main(void)
    {
    float actorname;
    float filmname;
    int bday;
    int releaseyear;
    int age
    int filmage;

    printf("What is the actors name?"\n);
    scanf("%s", actorname);
    printf("What is the film name?"\n);
    scanf("%s", filmname);
    printf("What is the actors birthday?"\n);
    scanf("%s", bday);
    printf("What is the films release year"\n);
    scanf("%s", releaseyear);

    bday - 2008 = age
    filmrelease - 2008 = filmage


    printf("When %s, actorname filmed %s, filmname he was %sage, years old. %s, actorname is currently %age, and he is a Zodiac sIGN, %sfilmname was made %s, filmage)


    }

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by newbiecoderguy View Post
    I know this is wrong but this is a basic structure I thought of

    Code:
    #include <stdio.h>
    int main(void)
    {
    	float actorname;
    	float filmname;
        int bday;
    	int releaseyear;
    	int age
    	int filmage;
    	
    	printf("What is the actors name?"\n);
    	scanf("&#37;s", actorname);
    	printf("What is the film name?"\n);
    	scanf("%s", filmname);
    	printf("What is the actors birthday?"\n);
    	scanf("%s", bday);
    	printf("What is the films release year"\n);
    	scanf("%s", releaseyear);
    	
    	bday - 2008 = age
    	filmrelease - 2008 = filmage
    	
    	
    	printf("When %s, actorname filmed %s, filmname 
            he was %sage, years old. %s, actorname is currently
           %age, and he is a Zodiac sIGN, %sfilmname was made %s, filmage)
    }
    You should pick up a book on Beginning C, and start with that. There is almost
    nothing right about your prototype program (even using code tags for the forum
    has eluded you).

    e.g.:
    1) Actor's name and film name are not floats, they're letters (char's), and go into
    arrays of
    Code:
    char: actors_name[40];
    scanf("%s", actors_name);
    2) bday - 2008 will not give you a correct age. It will give you a negative number,
    so swap them around. Same with filmage.

    What would be grand for your program is if you had the data in a file which was
    loaded into an array on start up. The data file would have the moves, the bday
    for each actor, the year the film was made, etc.

    Very few people will know the birthday of movie stars, or the year a film came out,
    once it gets past about five years. This would make your program much more
    challenging, but also, much more valuable.

    To use code tags, just highlight your program, and then click on the # char in the
    message window.
    Last edited by Adak; 07-02-2008 at 12:34 AM.

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    3
    Quote Originally Posted by Adak View Post
    You should pick up a book on Beginning C, and start with that. There is almost
    nothing right about your prototype program (even using code tags for the forum
    has eluded you).

    e.g.:
    1) Actor's name and film name are not floats, they're letters (char's), and go into
    arrays of
    Code:
    char: actors_name[40];
    scanf("%s", actors_name);
    2) bday - 2008 will not give you a correct age. It will give you a negative number,
    so swap them around. Same with filmage.

    What would be grand for your program is if you had the data in a file which was
    loaded into an array on start up. The data file would have the moves, the bday
    for each actor, the year the film was made, etc.

    Very few people will know the birthday of movie stars, or the year a film came out,
    once it gets past about five years. This would make your program much more
    challenging, but also, much more valuable.

    To use code tags, just highlight your program, and then click on the # char in the
    message window.
    Thanks for your input but the idea is that the person types in all the info, like searching wikipedia or IMDB and the program calculates their age at the time of the movie being released.

  5. #5
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Code:
    	
    printf("When %s, actorname filmed %s, filmname 
     he was %sage, years old. %s, actorname is currently
     %age, and he is a Zodiac sIGN, %sfilmname was made %s, filmage)
    Printf isn't used like that. It is used in a similar way as scanf. You should:
    Code:
    printf("blah blah %s blah blah %s", actorname, filmname);
    The actorname is printed instead of the first %s, the filmname instead of the second %s etc.
    Another thing you don't understand probably is that you don't use the %s for everything. If you want to have a number you should use the %d, that is for integers.
    Code:
            printf("What is the actors birthday?"\n);
    	scanf("%d", bday);
    And at last, I suppose you didn't compile the program. Start a little by little. One thing, compile, run. Another thing, compile, run. This way you will learn step by step what you do wrong and what not. The compiler errors will help you

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Take a while and read up on what you should not do with scanf.
    http://cpwiki.sourceforge.net/Common...kes_and_errors
    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. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I don't think anyone's mentioned yet that newlines (\n) should be inside the double-quoted string literals, like so:
    Code:
    printf("Hello, World!\n");
    Code:
    scanf("&#37;d", bday);
    Note, of course, that you'd need to use &bday. You need an & before every variable read with scanf(), except for strings.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program quits unexpected
    By skelesp in forum C Programming
    Replies: 34
    Last Post: 12-10-2008, 09:10 AM
  2. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  3. Replies: 3
    Last Post: 01-14-2003, 10:34 PM
  4. IDEA: Obfuscate a common program as much as possible
    By ygfperson in forum Contests Board
    Replies: 23
    Last Post: 01-11-2003, 10:30 PM
  5. IDEA: Redo a common program in a creative way
    By ygfperson in forum Contests Board
    Replies: 5
    Last Post: 08-16-2002, 08:38 AM