1 Replies - 518 Views - Last Post: 27 October 2013 - 11:10 AM Rate Topic: -----

#1 annleft  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1707
  • View blog
  • Posts: 3,275
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1