Thread: PLEASE help me with a code

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    9

    PLEASE help me with a code

    I some help, I need a simple C program ( not C++) that will ask somone to enter their name, middle and surname and their age.

    It needs to be fully trapped so if for example someone doesn't have a middle name it can be omitted.

    The results then need to be displayed on a screen, eg " the user of this programme is <first name><middle name><last name> aged <age>"

    PLEASE HELP, i have very, very little experience with programming.

    Thanks very much, I appreciate your help
    James

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well unfortunately for you, this is about as good as it's going to get right now. Here ya go:

    Quote Originally Posted by kermi3
    Welcome to the boards. If you haven't already done so then please take some time to familiarise yourself with the faq:
    http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

    Make sure you have a look at the the posting guidelines:
    http://cboard.cprogramming.com/annou...ouncementid=51
    Following the rules will ensure you get a prompt answer to your question.

    Remember, too, that the board has a search facility, a link is at the top of your screen:
    http://cboard.cprogramming.com/search.php
    It will often get you a quicker answer to your questions than waiting for a response to one you have posted.

    It appears that you are posting a homework assignment or other project.

    Please don't ask people to do all your work for you, See the announcement on Homework at the top of all forums to see what is acceptable or PM me. Basically people are happy to help, but they're not going to do it all for you.

    Show us what you've got, show your code (using code tags), or where you're confused and someone will be happy to help you I'm sure. If it's something that you absolutely don't understand how it works, like you have no clue how qsort works, then ask a general question about the function and I'm sure someone will explain it. Though they may not give you all of the code for it, but someone will explain the concept.


    On obivous homework questions especially, I like to remind people of the board's ninth guildeline, while this board is very helpful to people, make sure you have your instructor's permission before seeking help on assignments. While people on these boards are more than happy to help, we discourage people from asking for help on graded work without the instructor's permission, and we claim no repsonsibilty for any cheating or honor violations.

    Feel free to PM me with any questions.

    Good Luck,

    Kermi3

    Read and follow the above instructions, and try your post (in the same thread) again. Now we really mean for you to read all of that. Don't just brush it off, because that'll just make people not want to help you.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    9
    I am aware of this, its just I have no knowledge of C and I am trying to understand it more, if i got a start, then I may understand more!

    I was just being friendly , I thought somone might be able to help!

    JAmes

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    We can help. We do it all the time. However, as all of the above, (which I'm sure you've read, right?) states, you need to put forth some effort. I'm sure you came across in the FAQ, (as you were reading the above information, right?) ways to read information from the user. That alone, (which you've already read, right?) should easily get you started on your way. Then, when you get stuck (as described in the information you just got done reading, right?) you can post your code attempt, and we'll be more than happy to assist you.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Apr 2005
    Posts
    9
    ok, please give me 10 minutes whilst I type up what I have got so far, then maybe you could point me in the right direction please?

    James

  6. #6
    Registered User
    Join Date
    Apr 2005
    Posts
    9
    /* nameprogramme.c */
    /* jamesbrady, April 2005, U of G*/

    #include <stdio.h>
    main()
    {

  7. #7
    Registered User
    Join Date
    Apr 2004
    Posts
    173
    Firstly, make sure you explicitly state the return value for main to be int, and also if you are not accepting any arguments put a void in the parameter list like so:
    Code:
    int main(void)
    {
    If that's the only code you can write, then I suggest you start reading from a "Hello World" program and work your way down. Then you should move onto understanding variables, and try to at least understand the printf() and scanf() library functions.

  8. #8
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    Quote Originally Posted by 0rion
    Firstly, make sure you explicitly state the return value for main to be int, and also if you are not accepting any arguments put a void in the parameter list like so:
    Code:
    int main(void)
    {
    ..and let me that you now need to add a return statement, close your main function
    with '}'

    leaving you with
    Code:
    int main(void)
    {
         return 0;
    }
    Now compile!


    Congratulations! You just wasted 512KB!
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  9. #9
    Registered User
    Join Date
    Apr 2005
    Posts
    9
    Sorry, I pressed tab, then enter and it posted the code before I had the chance to finish it !!

    I have already done the 'hello world' one when i first started learning.

    Anyhow, this is what i got so far....

    -----------------------------------------------------
    Code:
    /* nameprogramme.c */
    /* jamesbrady, April 2005, U of G*/
    
    #include <stdio.h>
    int main()
    {
    cls
              printf (\t"please enter your first name : \n");
              scanf (\t ?????????? );
              printf (\t please enter your middle name : \n);
              scanf (\t ?????????? );
              printf (\t please enter your surname: \n);
              scanf (\t ?????????? );
              printf (\t please enter your age in numbers: \n);
              printf (\t Thank you ........ \n);
    
              printf (\t "The user of this programme is <name><middle name><surname> aged <age> \n");
    
    getch();
    }
    -------------------------------------------------

    i am confused as to how to assign a variable to ie a name and store it and then how to recall it when i have to display all the names. I have used scanf() but I can't remember how.

    james

  10. #10
    Registered User
    Join Date
    Apr 2004
    Posts
    173
    Misplaced >> Well I assumed he knew how to close and return the function - I only meant to demonstrate what he needed to change.

  11. #11
    Registered User
    Join Date
    Apr 2005
    Posts
    9
    Am I on the write track though?

  12. #12
    Registered User
    Join Date
    Apr 2004
    Posts
    173
    Firstly, you need the proper quotations around the printf() statements.
    So all the \t goes inside the " " like so:
    Code:
    printf ("\tplease enter your first name : \n");
    You need quotes for your other printf() functions as well.

    scanf() works by having a "format" as the first argument and the subsequent arguments are the locations where you want to "store" the respective formats.
    So if I wanted to read in an integer:

    Code:
    int num = 0;
    printf("Input an integer: ");
    scanf("%d",&num);
    
    printf("\nYou have inputted: %d",num);
    Not to mention: "cls" is out of place in your source, it is neither a function or variable. If you wanted it to "clear your screen" then I suggest you read the FAQ:
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

  13. #13
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    FAQ > How do I... (Level 1) > Get a line of text from the user/keyboard (C)
    FAQ > How do I... (Level 1) > How do I get a number from the user (C)
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by jamesbrady1003
    Am I on the write track though?
    I take it you totally ignored everything I suggested you read then huh? Otherwise you would have your answer by having read those links that Dave suggests you read. Now, for real this time, go read them.

    Quzah.
    Hope is the first step on the road to disappointment.

  15. #15
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    to learn to program and write code, you need:

    The willingess to read, a desire to learn, good reference material and know how to find good reference material, patience, and paper and pencil


    ........................maybe a computer too
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM