We changed our privacy policy. Read more.

Hot answers tagged

4

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 example: if (it's rainy) { get a coat } if (going to work) { use the car } You are checking for two different things. Instead: if (it's rainy) { ...


3

@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 bmp.h: #include <stdint.h> /** * Common Data Types * * The data types in this section are essentially aliases for C/C++ * primitive data types. * ...


2

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, and 224 is outside that range. You can use unsigned char or BYTE instead, which ranges from 0 to 255.


2

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 you tried help50? It might have told you about the same when called like help50 make music.


1

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 line number = number / pow(10,power) to be: number = beginningNumber / pow(10,power) Otherwise the variable number does the following (during the second while ...


1

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 break statement terminates execution of the smallest enclosing switch or iteration statement. In this case it terminates the the j loop and moves on to the ...


1

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 like this: IF card is VISA print VISA IF card is AMEX print AMEX IF card is MASTERCARD print MASTERCARD ELSE print INVALID Once it is ...


1

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 (a == (1 | 3 | 5 | 7 | 9 | 11 | 13))


1

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 look like an exercise from CS50x (or CS50ap). This forum focuses specifically on CS50 If you want to work on your skills in the c programming language, CS50x on ...


1

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] == 'A' && accidental == 'b') Since there's no curly brace pair {} associated with the if statement, only the first line following the closing parenthesis ...


1

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 strcmp () from the standard library string.h , its use is simple. The value returned by this function is zero if both strings are equal: #include <string.h&...


1

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 upper case letters This statement is ALWAYS true because of the OR operator. It should have been the AND operator, &&. If the code uses || to test for ...


1

{% 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 parameter with value to index.html, where it was checked {% if {{ empty }} == "False" %}` The idea is good, but it did not work. Apparently instead of {% if {{ ...


1

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]) > 0 && isspace(name[i + 1] == 0)) Specifically, look at the second clause: isspace(name[i + 1] == 0) Now, can you tell me what ...


1

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... } The reason your code produces no output, is the fact that islower() doesn't return a bool, but an int. Behind the scenes, true == 1 and false == 0, but ...


1

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.


1

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


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