Ok, so I have some code from my HugeInteger problem again. Like the title says this is totally backwards. I keep getting the exact wrong result than what should be given. I could probably sneek by the graders with it, but now it is really got me wondering. When I print out my array it is not zero, but the is zero line keeps printing unless I change the two cout statements around. Weird or just me?

f.isZero();
if (false)
   cout << "The huge integer is not zero." << endl;
else
   cout << "The huge integer is zero." << endl;

//The actual funtion I wrote is below. 

bool HugeInteger::isZero()
{
   for (int i=0; i<40; i++)
   {
      if ( digits[i] != 0 )
         return false;
   }
return true;
}

Recommended Answers

All 8 Replies

It's just a bit confusing. What you're doing is getting the isZero return value. If it is zero, this returns true (so it is zero). Then go to your if statement, and you put that true (it is zero) in there, then you go down and say it's not zero. Does that make sense?

It's just a bit confusing. What you're doing is getting the isZero return value. If it is zero, this returns true (so it is zero). Then go to your if statement, and you put that true (it is zero) in there, then you go down and say it's not zero. Does that make sense?

No, I am still confused. I even tried writing out what each was returning on paper. The false in both main and the functon should correlate and should say "not zero" because I have something in my array. It keeps telling me it is zero though.

Looking at the if statement:
if (false) // I'm assuming this means if it is false that the value is zero
cout << "The huge integer is not zero." << endl; // this line is skipped
else // program goes to else due to if(false), or is not zero
cout << "The huge integer is zero." << endl; // prints out is zero

Looking at the if statement:
if (false) // I'm assuming this means if it is false that the value is zero
cout << "The huge integer is not zero." << endl; // this line is skipped
else // program goes to else due to if(false), or is not zero
cout << "The huge integer is zero." << endl; // prints out is zero

So are you telling me that my if(false) statement is not right? If the if statement is correct why would it skip the first statement but do the second one?

The if statement will do the first part if the argument in its parenthesis is true. If not, it moves on to the else statement and does what it says in there. For example:

if( someBooleanValue )
cout << "This will appear if someBooleanValue is TRUE, but not if FALSE";

else
cout << "This will appear if someBooleanValue is FALSE, but not if TRUE";

The if statement will do the first part if the argument in its parenthesis is true. If not, it moves on to the else statement and does what it says in there. For example:

if( someBooleanValue )
cout << "This will appear if someBooleanValue is TRUE, but not if FALSE";

else
cout << "This will appear if someBooleanValue is FALSE, but not if TRUE";

but the statement that should be passed over and should activate the statement needed is not activating the right statement it is doing this for all of my boolean functions. It is soo confusing. Is there a less confusing way to get from what the boolean functions are returning to my cout statements?

but the statement that should be passed over and should activate the statement needed is not activating the right statement it is doing this for all of my boolean functions. It is soo confusing. Is there a less confusing way to get from what the boolean functions are returning to my cout statements?

Wait are you telling me my true statements have to be with my ifs and my false statements have to be with my elses?

Jeez! if (false) is always false because false is -- wait for it -- false!

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.