I am struggling horribly with functions and I am wondering if anyone can tell me why the following code does not display the value of dollar correctly. I have commented out the middle bit as I have know idea how to get that part going as a function.
Thanks heapsCode:#include <stdio.h> void GetData(float &change) { printf("Using intervals of five for the cents, please enter any amount of dollars and cents: $"); scanf("%f%*c", &change); return; } void SplitChange(int &dollar, int ¢s) { int change; dollar = (int) change; cents = (int) (((change - dollar)*100) + 0.5); return; } int main() { float change; int dollar, cents; const int ONEHUNDREDDOLLARS = 100, FIFTYDOLLARS = 50, TWENTYDOLLARS = 20, TENDOLLARS = 10, FIVEDOLLARS = 5, TWODOLLARS = 2, ONEDOLLAR = 1, FIFTYCENTS = 50, TWENTYCENTS = 20, TENCENTS = 10, FIVECENTS = 5; GetData(change); SplitChange(dollar, cents); /*printf("The notes and coins required to make change for %f\n dollars and cents are: ", change); while(dollar >= ONEHUNDREDDOLLARS) { printf("%d dollars ", ONEHUNDREDDOLLARS); dollar -= ONEHUNDREDDOLLARS; if(dollar > 0) printf(", "); } if(dollar >= FIFTYDOLLARS) { printf("%d dollars ", FIFTYDOLLARS); dollar -= FIFTYDOLLARS; if(dollar > 0) printf(", "); } while(dollar >= TWENTYDOLLARS) { printf("%d dollars ", TWENTYDOLLARS); dollar -= TWENTYDOLLARS; if(dollar > 0) printf(", "); } while(dollar >= TENDOLLARS) { printf("%d dollars ", TENDOLLARS); dollar -= TENDOLLARS; if(dollar > 0) printf(", "); } if(dollar >= FIVEDOLLARS) { printf("%d dollars ", FIVEDOLLARS); dollar -= FIVEDOLLARS; if(dollar > 0) printf(", "); } while(dollar >= TWODOLLARS) { printf("%d dollars ", TWODOLLARS); dollar -= TWODOLLARS; if(dollar > 0) printf(", "); } if(dollar >= ONEDOLLAR) { printf("%d dollar ", ONEDOLLAR); dollar -= ONEDOLLAR; if(dollar > 0) printf(", "); } if(cents >= FIFTYCENTS) { printf("%d cents ", FIFTYCENTS); cents -= FIFTYCENTS; if(cents > 0) printf(", "); } while(cents >= TWENTYCENTS) { printf("%d cents ", TWENTYCENTS); cents -= TWENTYCENTS; if(cents > 0) printf(", "); } if(cents >= TENCENTS) { printf("%d cents ", TENCENTS); cents -= TENCENTS; if(cents > 0) printf(", "); } if(cents >= FIVECENTS) { printf("%d cents ", FIVECENTS); cents -= FIVECENTS; if(cents > 0) printf(", "); }*/ printf("%d dollar ", dollar); return(0); }



LinkBack URL
About LinkBacks


