Like Tree3Likes
  • 3 Post By anduril462

Unknown Cause Small Program

This is a discussion on Unknown Cause Small Program within the C Programming forums, part of the General Programming Boards category; Hello peeps, You guys gonna have to bare with me as I am new to programing. My algorithms professor gave ...

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    4

    Unknown Cause Small Program

    Hello peeps, You guys gonna have to bare with me as I am new to programing.

    My algorithms professor gave us an assignment develop a program in C wich will take any integer and multiply it form 0 to 10. The problem is I only get the result in the command line prompt after I hit "ESC" and press "ENTER" I have no clue why, since I haven't messed at all with the debugger, can anybody shed some light?

    this is my code

    Code:
    #include <stdio.h>
    
    
    int main()
    {
        int x, multiply, result;
    
    
        printf("Multiply from 0 to 10:");
        scanf("%d\n", &x);
    
    
        for ( multiply = 0; multiply <= 10; multiply++ ) {
            
            result = x * multiply;
            printf("%d x %d = %d\n", x, multiply, result );
       
        }
        return 0;
    }
    Last edited by Marcos Curvello; 08-28-2012 at 08:58 AM.

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    You mean that printf at line 16 has no effect?

    In line 13 notice that you mul from 0 to 9 not from zero to ten,so you should use operator <= instead of <

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    4
    Thanks for the heads up mate! I just changed that and yes the printf at line 16 isn't working as it should, thats what I believe.

  4. #4
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    The scanf may be the problem.Remove the \n and recompile and run

  5. #5
    Registered User
    Join Date
    Aug 2012
    Posts
    4
    YAY it worked! thanks so much mate, simple solution seems so hard to find for newbies like myself haha thank you again! =)

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,457
    This program works for me, albeit with some strange input behavior, namely the ESC+ENTER bit. Try dropping the "\n" from your scanf.

    We need a better description than printf not "working as it should". Does it crash partway through? Does it output anything at all? Does it output some right numbers and some wrong numbers, or all wrong numbers? Please tell us what input you gave it, what output you expect and what output you actually get.

    Also, I'm not sure why you bring up the debugger. It's not the same thing as the command line prompt, nor should the input behavior be a result of "messing" with it. Either you're not explaining well what you're doing or you're just mixing up terms.

  7. #7
    Registered User
    Join Date
    Aug 2012
    Posts
    4
    Idk if you can read or you just messing around, the problemo is solved "it works buddy". If it wasn't for the help of std10093 I would presumably still be here, taken the way your responding to a thread. But thanks anyway for the help, this is my first post and sure won't be the last, as I gain knowledge I look forward to helping others as well.

  8. #8
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,457
    Quote Originally Posted by Marcos Curvello View Post
    Idk if you can read or you just messing around, the problemo is solved "it works buddy". If it wasn't for the help of std10093 I would presumably still be here, taken the way your responding to a thread. But thanks anyway for the help, this is my first post and sure won't be the last, as I gain knowledge I look forward to helping others as well.
    Some way to treat people that try to help you. I'm not sure why you think I'm such a big a-hole here. Had you taken a look at the time stamps on the response, you would have noticed my response was a mere minute or two after std10093's. It's not an issue of "can't read" or "messing around". I began it before they replied, but finished it after. I didn't know "it worked buddy" until after I posted my reply.

    You gave a poor description of the problem (printf not working as it should). You're new, I somewhat expect that, but I wanted to point out that it was poor, and provide some questions to clarify, and hopefully give you a hint as to how to ask better questions next time. The better your descriptions, the better help you get. A better first post, and std10093 would have had all of your problems fixed in one reply instead of having to ask you for more info.

    I gave what turned out to be the solution in my first paragraph, but also asked for more clarification in my second paragraph. It's very common for newbies here to give really bad and/or incomplete problem descriptions, and to encounter more than one problem, even with a program as short as yours. Often times they don't even post the exact same program they're having trouble with (they retype it instead of copy-pasting, introducing or removing problems they had on their own computer). I wanted to make sure we had all the information and could solve all your problems, hence my questions about the output.

    I know you're new to programming, so you're probably new to programming forums too. Had you read the forum guidelines thoroughly, including the links in the "Tips for Efficient and successful posting" section, you would have come across this: How To Ask Questions The Smart Way. I strongly recommend you read it if you plan on doing much more posting, it will help immensely. Also, get used to people being blunt or direct. It's not that we're mean, it's just that most of us don't screw around with pandering language to make the newbie feel all warm and fuzzy. We volunteer our time, while having jobs, families, etc, to help complete strangers. That's not exactly the prime demographic for a-holes. We're simply more interested in efficient, effective communication. We like helping people, and would rather spend it actually solving people's problems than prodding people for information the should have provided up front. We ask questions because we want/need to know the answer to them, or because when you answer them, it may help you find the answer to the larger problem. We tell you your post is confusing or you're misusing terms because it is or you are. Using language incorrectly makes communication difficult and we would prefer it otherwise.
    rags_to_riches, Salem and ZuK like this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomial program, Unknown Error.
    By protofarmer720 in forum C++ Programming
    Replies: 5
    Last Post: 06-14-2011, 01:24 AM
  2. Controlling an unknown program
    By bigdan43 in forum C++ Programming
    Replies: 3
    Last Post: 02-08-2005, 01:45 PM
  3. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  4. A small problem with a small program
    By Wetling in forum C Programming
    Replies: 7
    Last Post: 03-25-2002, 08:45 PM
  5. Need help with a small program
    By DenisGFX in forum C Programming
    Replies: 4
    Last Post: 02-02-2002, 09:47 AM

Tags for this Thread


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