Thread: Help with creation of program

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    39

    Help with creation of program

    Hello. Ive got an assignement on C programming n dnt know how to do it..can u help plzzz???

    This is the question:
    1. Design a program to input your name, a friend’s name and telephone number. Get the computer to print a message to you to phone your friend on the number given.

    PLzzz... if u can help me.. that will be gr8...

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Lemme guess. You didn't even start it.

    So pretend you're actually going to start it. Where would you start?

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    39

    Unhappy

    well I would have put this:
    void main ()

    ......Dont know what to put next....

    plzzz helpp.....

  4. #4
    Registered User
    Join Date
    Aug 2007
    Posts
    39
    whenever I write a C program I dunno why I get error at the printf and scanf command....

    This is why I would like someone to do the program that I posted n then I will be able to understand the codes...

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    First thing you should generally do is put this:

    Code:
    #include <stdio.h>
    
    int main(void)
    {
    	return 0;
    }
    Then you're ready to go.

    void main() is wrong, even though many compilers let you get away with it. It can cause problems later on when you want to debug a program and read its return value.

  6. #6
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by shaheel View Post
    well I would have put this:
    void main ()

    ......Dont know what to put next....

    plzzz helpp.....
    Well that is wrong, main returns an int, so it should be int main(void) or similar.

    Also, have you remembered to #include <stdio.h> - that might be why you get errors when using printf and scanf, if you have, then try and post the errors you get here.

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    39
    Thanks a lot.. well Ill keep this gud piece of advice in mind....

  8. #8
    Registered User
    Join Date
    Aug 2007
    Posts
    39
    well now.... wats the code for inputing my name, a friends name n tel number???

    Im getting CRAZYYYYYYYYYYYYYYYYYYYYYY.................

  9. #9
    uh oh
    Join Date
    Jan 2005
    Location
    Ontario, CA
    Posts
    66
    I believe what they are trying to tell you is, do your own homework. They have so far provided a skeleton for you to begin with, but they aren't going to do your homework for you. If you have missed it, place the following in to your chosen compiler and try yourself.

    Code:
    #include <stdio.h>
    
    int main(void)
    {
    return(0);
    }
    Now I'll throw another hint... your code will have to go before the return(0); line. If you have specific problems from that point on, please let us know so we can assist further, however, your problems with using printf should now be resolved considering the skeleton program now properly includes the correct headers. So give it a go and lets see if you can get an A on this project/assignment! I'm sure one of us can grade the attempt you make yourself.

    Regards

  10. #10
    Registered User
    Join Date
    Aug 2007
    Posts
    39
    well thanks due to the header theres no error about the printf command.. well I'll try to make the program ..after doin it I'll post the codes for u guys to chek it up for me...

  11. #11
    Registered User
    Join Date
    Aug 2007
    Posts
    39
    Here we r.. Im stuck here:

    Code:
    #include <stdio.h>
    
    int main(void)
    
    {
    	char my_name;
    
    	printf("Enter your name:");
    	scanf("&#37;d",& my_name);
    char friend_name;
    
    printf("Enter your friend's name:");
    scanf("%d",& friend_name);
    getchar();
    
    return 0;
    }

  12. #12
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Do you actually know C? Mashing the keyboard isn't going to get your homework done.

    * Use fgets() to get the user's PH and name - See the FAQ
    * See the FAQ on getting user input
    * If you want to get a char, use &#37;c, if you want a string (An array of chars) use %s

    Read the manual, and perhaps invest in a book.

  13. #13
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    char my_name;
    That is only creating a variable to hold 1 character, not a string.

    scanf("%d",& my_name);
    %d is for an int. %s is for a string, but first you'll have to fix my_name to be a string (i.e. array of characters) instead of just 1 character.

  14. #14
    Registered User
    Join Date
    Aug 2007
    Location
    Barbados
    Posts
    31
    Hi Everybody!
    This would be my very first post on this forum, so I decided to help shaheel.
    Forgive me if I do anything wrong, I don't know all the rules yet, I have read a few though.

    I have the feeling you may not know arrays Shaheel, and, for strings, you must include 'strings.h'.
    an array example :
    array[45] <- has 45 elements, starting at 0, you cannot write into number 45 though.

    And I agree with zacs7, get a book, O Reilly I hear has very good books.

  15. #15
    Registered User
    Join Date
    Aug 2007
    Posts
    39
    Hello everyone..I managed to write the program bUT I can get the last line to work properly:
    Code:
     /* Program 1*/
    
    #include <stdio.h>
    
    int main(void)
    {
    	char myname[20];
    	char friendname[20];
    	char telnum[7];
    
    
    	printf("Enter your name:");
    	gets(myname);
    	printf("Enter your friends name:");
    	gets(friendname);
    	printf("Enter your friends telephone number:");
    	gets(telnum);
    
    
    
    	printf(" &#37;c telephone %c on %c",myname,friendname,telnum);
    
    		return 0;
    }

    How to I put the code.. I want this line: "myname" telephone "friendname" on "telnum"

    Plzzzz help for this last bit..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM