指针的问题
Write a function which receives a pointer to the amount of money in your pocket and the price of a bus ticket. Function decrements
the amount of money by the price of a bus ticket only if you have
enough money. If you had enough money function returns non-zero value
and zero if you did not have enough money. The amount of money shall not
decremented if you don't have enough money.
Write a main program that uses this function.
#include <stdio.h>
#include <stdlib.h>
int buy_a_ticket( float *cash, float price )
{
*cash -= price;
if (cash > price)
return 1;
else
return 0;
}
int main()
{
float pocket=20.0, price=0.25;
printf( "my cash = $%.2f\n", pocket );
printf( "buy a tickect at $%.2f\n", price );
buy_a_ticket( &pocket, price );
printf( "cash remaining = $%.2f\n", pocket );
return 0;
}
不太对,请教应该怎么改,题目也不是很明白,难道要分别提问口袋里和车票有多少钱?