Hot answers tagged

4 votes
Accepted

when to use a series of ifs and when to use if/else if/else?

You use two consecutive ifs, if you want your program to two things independently of one another. In the other hand you use if/else if/else, if you want only one of this things to be executed. For ...
user avatar
  • 7,326
3 votes
Accepted

Pset4 recover, comparing hex in if statements

@Blauelf is correct: you can't count on char to be an unsigned 8-bit int. However, you can use a typedef to make certain that a BYTE is really a byte. Look at these type definitions, borrowed from ...
user avatar
  • 3,036
2 votes

Pset4 recover, comparing hex in if statements

char can be signed or unsigned by default (and is 8-bit on every system I know, but that's not guaranteed by the specs). On this system, char datatype is signed 8-bit int, ranging from -128 to 127, ...
user avatar
  • 20.7k
2 votes
Accepted

control reaches end of non-void function

This error message means "Your function is declared as returning a value of type int, but it's possible it might return not at all". Make sure control flow always ends in a return statement. Have ...
user avatar
  • 20.7k
1 vote

credit pset1 cs50 sum while loop

A problem I found is at line 47 of the code (the second while loop): while (power <= 14) { sum += (number % 10); power += 2; number = number / pow(10,power); } I think you meant the ...
user avatar
1 vote
Accepted

what is the significance of break; in tabulate function?

Each round counts one vote per voter, for their top preferred, non-eliminated candidate. Once that vote is counted, program moves on to the next voter. From the C99 standard section 6.8.6.3: A ...
user avatar
1 vote

pset1 - credit - if-else statement issue

The (only) else clause executes after the MASTERCARD code; if a card was already determined to be VISA or AMEX, it will not be MASTERCARD, therefore, will execute that else. In pseudo code something ...
user avatar
1 vote

Receiving 'error: expected expression' for code inside if statement (pset1)

To evaluate the right side first we must put the parentheses on the right side of the identity, not the operator == itself if (counterCardLength == 15 && FindFirstTwoDigits == (34 | 37)) if (...
user avatar
  • 5,172
1 vote
Accepted

Output of characters at specific place place using uint_list

If you want to print something different based on a condition, you need to use a conditional like an if. As written this program will only ever output (sign) and 5 dashes. Full stop. This does not ...
user avatar
1 vote
Accepted

Why are these if-else statements not letting my program compile?

Look at the following code: if(octave == 4) { if(note[0] == 'A' && accidental == '#') answer = (440 * pow((double)2, (double)1/12)); return answer; else if(note[0] == ...
user avatar
  • 64.2k
1 vote
Accepted

Pset 2 Crack: If statement doesn't check password correctly

From the context I suppose you want to compare two strings, this can not be done with the == operator (only compare two pointers, which in this case are not the same). You will need a function called ...
user avatar
  • 5,172
1 vote
Accepted

PSET2 Caesar Bug in Uppercase Case For Loop

I've been trying to step through the code to duplicate what happens with no success, but I have a couple ideas. First, look at the following: if (plain [i] >= 66 || plain[i] <=90) //case for ...
user avatar
  • 64.2k
1 vote

How to disable a table (portfolio) in index.html?

{% block main %} {% if empty == "False" %} // TODO Somethig <p>NOOO</p> {% endif %} {% endblock %} Easy fix I was trying to to pass a variable empty as a ...
user avatar
1 vote
Accepted

pset2 initials if statement not checking

No, actually, the test condition is almost never true. But I can see why you'd think it is. Funny how it's always in the details! Look very closely at the test code: if ( isspace(name[i]) &...
user avatar
  • 64.2k
1 vote
Accepted

PSET 2: Nested IF statement

You have made a mistake that is very frequent among novice programmers, you check for the returned bool using ==. You should instead use something like: if (islower(text[i])) { // do things... } ...
user avatar
  • 7,326
1 vote

Understanding continue statement in while loop in (pset6)

Ok well... that was quite the oversight... realized immediately after posting the question. if dprintf is successfull continue never gets called. which is what should happen.
user avatar
  • 159
1 vote
Accepted

Having issues with a scratch "If" function

The monkey can never get to x < -220 so the else condition is never met. Try changing it to -180 or so.
user avatar
  • 18.4k

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