Skip to content

Instantly share code, notes, and snippets.

@criscokid
Created November 19, 2010 14:59
Show Gist options
  • Save criscokid/706612 to your computer and use it in GitHub Desktop.
Save criscokid/706612 to your computer and use it in GitHub Desktop.
Square Test
int main() {
int dollars, cents;
float paid = 4.00f;
float price = 3.10f;
int paidInt = paid * 100;
int priceInt = price * 100;
int changeInt = paidInt - priceInt;
dollars = (float)changeInt / 100;
cents = changeInt % 100;
printf("change = %d.%d\n", dollars, cents);
return 0;
}
/*
* If you pay $4.00 for a latte that costs
* $3.10, how much change do you get?
*/
int main() {
float change = 4.00f - 3.10f;
printf("change = %10.10f\n", change);
return 0;
}
// => 0.9000000954
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment