Assignment HELP!!

This is a discussion on Assignment HELP!! within the C Programming forums, part of the General Programming Boards category; Originally Posted by cprogrammer22 Cannot get the function to add my numbers.. So at some point you learned to add, ...

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by cprogrammer22 View Post
    Cannot get the function to add my numbers..
    So at some point you learned to add, right? If I give you
    Code:
       198465412
    + 2376418749
      ----------
    how do you add numbers together?

  2. #17
    Registered User
    Join Date
    Nov 2008
    Posts
    31
    yeah i know how to add im having trouble with the function, im not gettin the numbers added when i call it and not sure if i use a for loop or what?

  3. #18
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Somethings very fishy here!

    Your functions name is "print", but you call something called "printf()":
    Code:
            printf(string1);//call function to print out information
    which should have given you a compiler error a mile wide!

    If you aren't receiving compiler errors, you need to fix that with your compiler. If you *are* receiving compiler errors, you need to pay attention to them.

    Fix this, and post up a sample of your input and output, please, so we're all on the same page here.

  4. #19
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by Adak View Post
    Somethings very fishy here!

    Your functions name is "print", but you call something called "printf()":
    Code:
            printf(string1);//call function to print out information
    which should have given you a compiler error a mile wide!

    If you aren't receiving compiler errors, you need to fix that with your compiler. If you *are* receiving compiler errors, you need to pay attention to them.

    Fix this, and post up a sample of your input and output, please, so we're all on the same page here.
    What reason do you see to get a compiler error here?
    first parameter of printf is format - const char*

    string1 is char*

    other parameters are optional.

    So what could compiler complain here about?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #20
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by cprogrammer22 View Post
    yeah i know how to add im having trouble with the function, im not gettin the numbers added when i call it and not sure if i use a for loop or what?
    So write down on a piece of paper how you would add numbers together. Look for patterns that can be abstracted into a loop. Figure out where you have to start and where you have to stop (not as trivial as it sounds, I would bet).

  6. #21
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    It looked to me like he meant to call his own function "print", but misspelled it as printf, just out of C syntax habit.

    I don't understand why you'd have a note about "//calling the function", in the code, when you were just using printf() to print one char string. BFD.

  7. #22
    Registered User
    Join Date
    Nov 2008
    Posts
    31
    if i call my original print function wont it print the numbers is reverse order since i did that before? i dont think i have the numbers set up to add correctly. im changing my add function call in main to

    add(p, q);

  8. #23
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by Adak View Post
    It looked to me like he meant to call his own function "print", but misspelled it as printf, just out of C syntax habit.

    I don't understand why you'd have a note about "//calling the function", in the code, when you were just using printf() to print one char string. BFD.
    It could be a mistake - using prinf insttead of home made print
    It could be a bad habbit - using custom string in printf instead of
    Code:
    printf("%s", string1);
    which is more stable and thus should be recomended.

    But it is not my point - my point was - compiler could not determine the first error because the prototype of the printf was match.
    Maximum it could warn about the second issue - but it should be very sofisticated compiler
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  9. #24
    Registered User
    Join Date
    Nov 2008
    Posts
    31
    i cant print out the two numbers i want to add still with the add(p, q);

  10. #25
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by cprogrammer22 View Post
    i cant print out the two numbers i want to add still with the add(p, q);
    Is this some kind of encrypted question?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  11. #26
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by cprogrammer22 View Post
    i cant print out the two numbers i want to add still with the add(p, q);
    Can you post what the code is right now? Also, please explain is your problem in the printing of the strings, the printing of the answer, or getting the two strings of digits added together into one sum?

    Vart: I've never seen printf() with just a pointer inside, and no formatting info. If you say it works, that's good enough for me.

  12. #27
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    Quote Originally Posted by Adak
    I've never seen printf() with just a pointer inside, and no formatting info.
    This would be the case when the format string has no format specifiers. The pointer is presumably a pointer to the first character of the format string.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #28
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Well - that's just wrong! ROFL!!

  14. #29
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Adak View Post
    Well - that's just wrong! ROFL!!
    You may dimly remember:
    Code:
    printf("Hello, world!\n");

  15. #30
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Sure Tabstop - start the highly technical, complex arguments. What a pal you are!!

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 08:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 01:21 PM

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