# Print only negative numbers using a function

Page 1 of 1

## 1 Replies - 1557 Views - Last Post: 27 October 2013 - 11:10 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=332567&amp;s=b14f1ed4008856078cd800bb6ac094f7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 annleft

Reputation: 0
• Posts: 9
• Joined: 18-September 13

# Print only negative numbers using a function

Posted 27 October 2013 - 10:59 AM

```#include <stdio.h>

void negative_count(long num1, long num2);

int main(void)
{
long num1;
long num2;
printf("Please enter two long integer values: \n");
scanf("%ld %ld", &num1, &num2);
negative_count(num1,num2);

getch();
return 0;
}

void negative_count(long num1,long num2)
{
int num3 = 0;
if((num1 < 0) && (num2 < 0))
{
num3 = 2;
printf("The number is %d", num3);
}
else((num1 < 0) || (num2 < 0));
{
num3 = 1;
printf("Number of negative numbers entered is %ld", num3);
}
num3 = 0;
printf("Number of negative numbers entered is %ld", num3);
}

```

Hello All - I would like to get this program to read and print only the negative numbers entered using a function. I have tried moving the if else statements but it continues to print both lines if both answers are true. Could someone please look at it and guide me in the right direction.

Thanks,

Ann

Is This A Good Question/Topic? 0

## Replies To: Print only negative numbers using a function

### #2 Salem_c

• void main'ers are DOOMED

Reputation: 2030
• Posts: 3,997
• Joined: 30-May 10

## Re: Print only negative numbers using a function

Posted 27 October 2013 - 11:10 AM

> 25 else((num1 < 0) || (num2 < 0));
1. The final else doesn't have a condition.
2. The trailing ; just makes things worse.