4 votes
Accepted

How to fix the "expression result unused" compilation error?

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; ...
user avatar
  • 64.1k
3 votes
Accepted

Why does this program output 0?

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 ...
user avatar
  • 18.4k
2 votes
Accepted

PSET6 Load - How To Approach? Also, Is It Better To Use While() Loop or For() Loop?

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 ...
user avatar
2 votes
Accepted

Pset3 breakout issue with the while live > 0 && bricks > 0

Try initializing your velocity outside the loop. Right now you are reinitializing it every iteration of the loop, so your velocity is always 2.0, and is never changing.
user avatar
  • 71
2 votes
Accepted

Do/while loop gives error of unused variable, pset1

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 ...
user avatar
  • 17.4k
2 votes
Accepted

pset2 Crack - Looping through fgets

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 ...
user avatar
  • 7,326
2 votes
Accepted

while loop executes randomly

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 ...
user avatar
1 vote
Accepted

PSet1 While Loop to Print Spaces for Mario Not Working

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 ...
user avatar
  • 20.7k
1 vote
Accepted

What is the problem with my get_int for the lab 1 question population in C?

That program will end if a value greater than 8 is entered for x. The return x; returns from the main function, which is to say program ends. Ditto the return y;. return is the statement that ends a ...
user avatar
1 vote

While loop for recover pset4

Fread() function allows you to iterate over file if combining with the while loop. Basically the fread() function will look at the file and search for a block size of 1 byte 512 times or similarly you ...
user avatar
  • 63
1 vote
Accepted

Pset1 Cash Understanding modulo operator and while loops

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 ...
user avatar
  • 64.1k
1 vote

Stumped on pset1 cash.c, please help me learn

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'...
user avatar
  • 64.1k

Only top scored, non community-wiki answers of a minimum length are eligible