Recently in my C class we learned about functions and pass by reference and I have a question about a function in my programming assignment.
Code:
//Pre-conditions: numchips > 0.
//Post-conditions: Returns the cash obtained for selling
// numchips number of chips.
int sellchips(int *numchips_ptr) {
int chips_sell;
int money_sell;
int cash_pst_sell;
printf("How many chips do you want to sell?\n");
scanf("%d", &chips_sell);
if (*numchips_ptr > 0 && *numchips_ptr >= chips_sell) {
*numchips_ptr = *numchips_ptr - chips_sell;
money_sell = chips_sell * SELL_VALUE;
printf("$%d\n", money_sell);
}
else {
printf("Sorry, you do not have that many chips. No chips sold.\n");
}
}
it updates the number of chips in my main fine but I'm having trouble initializing another pointer for the amount of cash the user has so i can manipulate that value.
additionally, i have the amount, money_sell, that i'm supposed to add on to cash...
i've tried multiple attempts at initializing another function with a pointer towards cash then calling it in the above function but i'm not sure how that's supposed to work out.
any help would be greatly appreciated