function - Why am I getting garbage when I use pointers in this program? C Language -


I am trying to get an understanding of the language syntax and I do not understand why I am getting garbage.

< P> Value when I use the pointer in this function.
  # include & lt; Stdio.h & gt; # Include & lt; Math.h> Zero different (double, double * dollar, double * quarter, double * coins, double * nickel, double * money); Int main (zero) {double sum = 38.39, change, payment = 40.0, dollar, quarter, money, nickel, money; Change = payment - amount; Separate (change, & dollar, and quarter, & coin, & nickle, & money); Printf ("Your total change is: $% d \ n", changing); Printf ("dollar:% d \ n", dollar); Printf ("Quarter:% d \ n", quarter); Printf ("dimes:% d \ n", dim); Printf ("Copy:% d \ n", turned out); Printf ("Pennies:% d \ n", Panny); Getchar (); Return (0); } Zero different (double change, double * dollar, double * quarter, double * coins, double * nickel, double * money) {double coins; Coins = change - floor (change); * Dollar = floor (change); * Quarter = coins / 25; Coins = Coins - (* Quarter * 25); * Coins = Coins / 10; Coins = Coins - (* Money * 10); * Nickel = Coins / 5; * Pani = Coins - (* Nickel * 5); }    

I suspect that your problem is that you do not split correctly

Take a look:

  different (double change, double * dollar, double * quarter, double * coins, double * nickel, double * money) { // For your example, changes are initially 1.61 double coins; Coins = change - floor (change); // .61 * dollar = floor (change); // 1 * quarter = coins / 25; // .0244 coins = coins - (* quarter * 25); // 0 * time = coins / 10; // 0 coins = coins - (* money * 10); // 0 * nickel = coins / 5; // 0 * pendant = coins - (* nickel * 5); // 0}   

Integer divisions and floating point divisions do not work in the same way. You should increase the number instead of 100, to get the number of cents, get the number of 25 from the quarters, then floor it to make the whole number.

  * quarters = floor (coins * (100/25)); // floor (2.44) = 2 coins = coins - * quarters * 25; // .11   

Repeatly to get the amount of other coins.

In addition to that, everyone else mentioned that you % d to print the combinations instead of % f

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -