It's because you did a calculation and didn't do anything with it. You have cents - 25; Where are you putting the result?
All of these would work:
int change = cents - 25;
cents = cents - 25;
cents -= 25;
The infinite loop is another story. To fix that loop, you'd use either of the latter two.
If this answers your question, please accept this answer to ...
It actually prints 4,8,16,32,64 etc. until it hits the maximum integer value of 232-1 and from then on, it can only print 0 because you've overflowed the integer. It happens so quickly that you miss the first numbers.
Try substituting the while loop with a for loop so you can see what happens.
int main (void)
int x = 2;
Q1. Should I use fgetc() or fread()
A1.: You can make both work! Choose the one you're more comfortable with.
Q2. I don't know whether to use a for loop or a while loop. Is one better for this pset?
A2.: In C you can translate a for loop to a while loop and vice-versa. So, again, choose the one you like best.
Here's some pseudocode for you to ...
Well, you're not actually using the variable that's declared inside of the loop, but we'll get to that. Here is a couple of points
Every loop has a continuation condition (the one between the parentheses after while in this case). As long as this condition is true, the loop will continue executing. The do...while loop is special in the sense that it always ...
Let's take a look at the man page of strcat():
char *strcat(char *dest, const char *src);
The strcat() function appends the src string to the dest
string, overwriting the terminating null byte ('\0') at the end of
dest, and adds a terminating null byte.
So, it seems that strcat() doesn't just return to you a new string with the result of the ...
The while loop is not random. The sort function doesn't handle duplicates (ie values[i] == values[i + 1]) so the while loop goes "infinite" because if( sortcount == (n - 1) ) is never true. I suspect if you run the program 10 times in a row with 100, it will eventually fail. As n gets bigger, it is more likely there will be duplicates in randomNumbers.
You have created an infinite loop. If the loop starts, it will never exit the loop. It tests the value contained in amount to decide to continue or exit, but since the value of amount is not changed inside the loop, it will never exit. You either need to change the value of amount inside the loop or you need to use an if statement instead, so that it only ...
More accurately, it isn't counting pennies correctly. In fact, it isn't counting a lot of things correctly. (Try $4.20) The cause of the problem is the whole purpose of this pset. Because of that, I'll suggest going back and reviewing the class lectures and other material related to the inaccurate storage of floats.
Hint: try printing out the value of f ...
For the first inner loop, use a while loop, not do..while, as you don't want any space printed in front on the last line.
The difference between while and do..while is that the do..while runs at least once.
Here, I'd prefer for loops instead.