PDA

View Full Version : Why? Invalid type argument of unary *



progman
21st March 2011, 16:23
K, I can't wrap my head around why this error keeps popping up. I am writing a conversion program and thanks to some prior help, I am able to start calculating some values, but I've run into a bit of a snag. Examples below:

My defines:


#define ACRE_SQ_CHAIN 10;
#define ACRE_RODS 160;
#define ACRE_SQ_LINKS 10000;
#define ACRE_HECTARE 0.4047;


and the calculation routine - this works:


if(to == "Hectare")
{
cvrt = temp * ACRE_HECTARE;
answer.setNum(cvrt);
leAcreAns->setText(answer);
}


This doesn't work:


if(to == "Rods")
{
cvrt = temp / ACRE_SQ_CHAIN * ACRE_RODS;
answer.setNum(cvrt);
leAcreAns->setText(answer);
}

This is the section that is throwing the 'unary error'. If I change ACRE_RODS to the actual hard coded value, that is 160, error still occurs. Why is it that in some cases, it figures out I want to multiply the values, but in other cases, it thinks there is a unary * issue....

If you look at the first section where it have temp * ACRE_HECTARE, that works fine, but, if I reverse it, so that it reads, ACRE_HECTARE * temp, it also throws the unary* error? What am I not seeing??

Thanks!

high_flyer
21st March 2011, 16:27
remove the ';' from your defines.
what you get is:

cvrt = temp / 10; * 160;;

Rhayader
21st March 2011, 16:32
Make a google search for "const instead Define". It is more than a matter of style

progman
21st March 2011, 16:35
remove the ';' from your defines.
what you get is:

cvrt = temp / 10; * 160;;

** Smacks head against desk ** Thanks!

Rhayader
21st March 2011, 20:31
progman, thanks for the thanks but I think you should thank high_flyer instead