Thread: Assignment HELP!!

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #20
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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,336
    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!!

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, 09:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 01:21 PM