Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

An integral expression is needed...? 1

Status
Not open for further replies.

TFfan

Programmer
Jan 18, 2002
192
CA
That's the error message that I get. The error points to
these two lines:

total=(w+x+y+z);
PrintResults (w+x, y+z, w+x+y+z);

or, more specifically, the second value in each clause (ie. the 'x' in w+x+y+z, the 'x' in w+x, the 'z' in y+z, and the 'x' in w+x+y+z).

Is it asking for an interger value or something else? These expressions worked before I changed the program to use call by reference. Thanks.


void calculateExpenses(int *w, int *x, int *y, int *z) { /* the function definition */
total=(w+x+y+z);
PrintResults (w+x, y+z, w+x+y+z);

}
void PrintResults(int t, int b, int tot){ /* the function definition */
printf("\n");
printf("Travelling Expenses for %s are %d\n", dest, &t);
printf("Boarding Expenses for %s are %d\n", dest, &b);
printf("\n");
printf("The total expenses for %s are %d\n", dest, &tot);
printf("\n");
}
 
I figured it out--a pretty stupid oversight that took me two days to see. Thanks just the same.
 
hi,
change parameter passing mode from value to reference,
is not as change the color of a shirt:
what was good for one, is not for the other.

In above case, is better pass argument by value:
you have only 4 int to pass, and passing by val or ref.
consumes the same (you have not big structure);
moreover it does not return (modifies) value.

If you back to
void calculateExpenses(int w, int x, int y, int z)
what is inside is good.

If you leave (int *w, int *x ....
you have to:

int total = *w + *x + *y + *z ;
PrintResults (*w+*x, *y+*z, *w+*x+*y+*z);

Then, use ref passing for string, big structures, or
when the routine changes (returns) values.

B Y E
 
Your solution is better than mine (no surprise there!). Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top