:?: can anyone tell me where the error is?

#include<iostream.h>
#include<conio.h>

void main()
{
 clrscr();
void zero_small(int &,int &);
int a,b;


cout<<"\n\n\n\tEnter the first no  ";
cin>>a;
cout<< "\n\n\n\tEnter the second no  ";
cin>>b;

 zero_small(a,b);
cout<<"\n\n\n\tValue of the first no is "<<a;
cout<<"\n\n\n\tValue of the second no is  "<<b;
getch();
}


void  zero_small(int& a,int &b  )
{
 if (a<b)
  {a==0;  }
else b==0;

return;
}

Recommended Answers

All 7 Replies

Member Avatar for iamthwee

> can anyone tell me where the error is?
Erm, maybe your logic amongst other things?

I mean what were you expecting the function to do:

void  zero_small ( int& a, int &b  )
{
   if ( a < b )
   {
      a == 0;
   }
   else b == 0;

   return;
}

i wanted to print the smaller no as 0..thatz why i did that..is that wrong?

Member Avatar for iamthwee

Well why do you have a return in the function, you shouldn't need one because you are passing back by reference.

You don't use the double equal sign if you are setting a value to a variable.

This is how I might do it.

#include <iostream.h>

void zero_small ( int &a, int &b )
{
  if ( a < b )
  {
    a = 0; //one equal sign not double!
  }
  else b = 0;
 //no returns
}

int main()
{
  int a;
  int b;

  cout << "\n\n\n\tEnter the first no  ";
  cin >> a;
  cout << "\n\n\n\tEnter the second no  ";
  cin >> b; 
  zero_small ( a, b );

  cout << "\n\n\n\tValue of the first no is " << a;
  cout << "\n\n\n\tValue of the second no is  " << b;

  getchar();
  getchar();
  return 0;
}

I agree with iamthwee. There seems no point in that segment of code! It checks a relation: if a is equal to zero or not, if a is less than b, otherwise it relates b to 0, which is pointless.

Is the code meant to say, check a==(some integer) and then print a=some expression, in the case that a<b, or something?

Or - you are trying to assign a or b to 0, in which case it would be a=0 or b=0, not the relational operator ==.


EDIT//oops! sorry for posting this, i think the top two posts were posted as i was writing this!

Well why do you have a return in the function, you shouldn't need one because you are passing back by reference.

Wait, I'm not sure if he edited the code in the first post, but the function just had return; , not return someVal; . It's not neccesary to include the return; statement at the end of a void function, but I sometimes put it just so I'm controlling when the function returns, not the end curly bracket. Is that considered "wrong" or weird?

>Is that considered "wrong" or weird?
Falling off the end of a function automatically returns, so it's weird in that people don't expect to see that kind of redundancy in well written code. It's not wrong though.

thank u !!...i got de point!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.