Context;
I'm trying to solve Cash by;
Taking positive integer user input, saves as float "ch" for change. (this as an implementation detail)
Create an array "coin_val" with coin value by descending order (so 25c, 10c, 5c, 1c). This array has a parameterised index integer "i" initialised to 0.
do while-loop that stops when "i" is > 3. step 4 is nested in this loop.
while-loop that stops if the current "coin_val" is greater than the current total "ch" and increments a coin counting int, "coin", by 1 when "coin_val" is less than "ch".
(After step 4 while-loop, and nested in the do-while-loop (step 3)) Increments "i".
Once the do while-loop is complete (and the change has been counted out) the "coin" total prints.
I'm pretty sure I don't need to be implementing arrays for this pset but doing 4 of the same while-loops for each coin value seems stupid and repetitive, and it seems like a good thing to practice arrays on before pset2. (I'm trying this because I watched the week 2 lecture on arrays, but I stupidly missed this part of pset1, so I'm back to get it done before I try pset2). I could probably make the array and the coin counting loop into an implementation detail also, and make main more succinct, but I can't get this set up to work so I haven't tried yet.
Here's what I'm on about;
// array
float coin_val[] = {0.25, 0.10, 0.05, 0.01};
int i = 0;
// get user input for change
float ch = get_pos_float();
int coin = 0;
// while index position of array is <= length of array
do
{
// inner loop that deducts current coin from change, ends when coin is larger than change
while(ch > i)
{
ch = ch - coin_val;
coin++;
}
coin_val[i++];
}
while(i < 3);
printf("Coin total: %i\n", coin);
My problem is that the compiler returns;
error: expression result unused [-Werror,-Wunused-value]
coin_val[i++];
~~~~~~~~ ~~~^
This might be a simple problem, although I don't feel like I fully understand how incrementing arrays works yet, so I don't understand where I'm going wrong.
I would greatly appreciate any help, I think my solution is better, and don't want to settle for writing repetitive code just because it's easier. Similarly, if this is a lesson for later in the course and something I don't need to worry about yet, please tell me to stop being so enthusiastic and solve the problem the lazy way. Cheers!