Thread: Need help! can't see my error!

  1. #1
    Registered User
    Join Date
    Oct 2014
    Posts
    2

    Unhappy Need help! can't see my error!

    I wrote a program where i have to input 4 integers, which will have their last digit added up and then the program will print out that the sum of the last digits is either even or odd. (e.g. The program basically has to say " The sum of the last digits of x,x,x, and x is even"). this is what i have so far but it won't print out what i want it to say. Any suggestions?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int even_odd(int num1, int num2, int num3, int num4);
    
    int
    main(void)
    {
        int w,x,y,z;
        
        printf("Please enter first integer:\n");
        scanf("%d",&w);
        printf("Please enter a second integer:\n");
        scanf("%d", &x);
        printf("Please enter a third integer:\n");
        scanf("%d", &y);
        printf("Please enter a fourth integer:\n");
        scanf("%d", &z);
        
        int even_odd(int w,int x,int y,int z);
        
        
    }
    
    int even_odd(int num1, int num2, int num3, int num4)
    {
        int w = (num1%10);
        int x = (num2%10);
        int y = (num3%10);
        int z = (num4%10);
        
        int n = w+x+y+z;
        if(n%2 == 0)
            printf("The sum of the last digits of %d,%d,%d,and %d.\n is even", w,x,y,z);
        else
            printf("The sum of the last digits of %d,%d,%d,and %d.\n is odd", w,x,y,z);
        
        system("pause");
        return(0);
        
    }

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    88
    Where is the call to even_odd(...) ? line 21 is not a function call , it's a prototype.

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Code:
    int main(void)
    {
        int w,x,y,z;
    
        printf("Please enter first integer:\n");
        scanf("%d",&w);
        printf("Please enter a second integer:\n");
        scanf("%d", &x);
        printf("Please enter a third integer:\n");
        scanf("%d", &y);
        printf("Please enter a fourth integer:\n");
        scanf("%d", &z);
    
        even_odd(w,x,y,z);
    
        return 0;
    }
    Note how I call "even_odd" and main returns "0" on success.
    Fact - Beethoven wrote his first symphony in C

  4. #4
    Registered User
    Join Date
    Oct 2014
    Posts
    2
    Thanks man that makes sense! 😄

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 10-29-2012, 03:33 AM
  2. Replies: 15
    Last Post: 11-28-2011, 11:48 AM
  3. Replies: 4
    Last Post: 07-24-2011, 09:38 PM
  4. Replies: 1
    Last Post: 11-15-2010, 11:14 AM
  5. Replies: 3
    Last Post: 10-02-2007, 09:12 PM

Tags for this Thread