Thread: Trouble with addition program with user input

  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    5

    Trouble with addition program with user input

    Hi, I just started learning C and I'm not sure why the program isn't working

    Code:
    #include <stdio.h>
    
    
    int
    main(void)
    {
        printf("Enter two numbers>");
        scanf("%d%d, &m, &n)");
        
        m = m + 5;
        n = 3 * n;
        printf("m = %d \n n = %d \n", m, n);
        return(0);
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Where have you declared your variables m and n? Your compiler should be telling you why the program won't compile. In future posting these messages exactly as they appear in your development system will help us help you.


    Jim

  3. #3
    Registered User
    Join Date
    Sep 2014
    Posts
    5
    I didn't realize I left it out, but even when I add it in, it doesn't seem to work. I'm not sure what I'm doing wrong. Here's my code with declared variables
    Code:
    #include <stdio.h>
    
    
    int
    main(void)
    {
        int m, n;
        printf("Enter two numbers>");
        scanf("%d%d, &m, &n)");
        m = m + 5;
        n = 3 * n;
        printf("m = %d \n n = %d \n", m, n);
        return(0);
    }
    thanks

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Look closely at your scanf() call. Are the parentheses and quotation marks in the correct locations?

    Jim

  5. #5
    Registered User
    Join Date
    Sep 2014
    Posts
    5
    thanks i finally got it!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 07-19-2012, 08:52 PM
  2. Want User Input but Program Ends
    By completenewbieu in forum C Programming
    Replies: 5
    Last Post: 08-29-2011, 04:10 PM
  3. Replies: 3
    Last Post: 10-12-2010, 01:40 PM
  4. Trouble with error checking on input from user.
    By NuNn in forum C Programming
    Replies: 8
    Last Post: 01-23-2009, 12:59 PM
  5. user input and program design
    By Chaplin27 in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2005, 08:53 AM

Tags for this Thread