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

Vigenere Segmentation understanding

This is a very, very common error for new programmers. The problem is the actual call to isalpha(). The isalpha() function takes a single char as input, but argv[1] is a string, not a char. Simply ...
user avatar
  • 63.4k
2 votes

"Control may reach end of non-void function" but I'm sure my else statements take care of it?

Consider following question: what happens, if there is no value in values[]? In such case, assuming n is greater than 0, we would never reach any of the return statements: First one wouldn't get ...
user avatar
2 votes
Accepted

PSET2 Vigenere: Output bug, keyword loop going over strlen of key

There are a number of problems with this code. Let's deal with your question first. The code is constructed as a nested pair of loops. The outer for loop will loop over the length of the plain text ...
user avatar
  • 63.4k
1 vote
Accepted

Nothing prints in Mario Problem

You have set up the while condition incorrectly. Your do/while loop is this: do { ... } while (h>=1 || h<=8); You have essentially created an infinite loop. Think about the test ...
user avatar
  • 63.4k
1 vote

PSET2 Vigenere: Output bug, keyword loop going over strlen of key

I would recommend you to do this problem set in one for loop. You can just loop through the plaintext. Using nested loops will make the problem more complicates than you think. It's because you only ...
user avatar
  • 55
1 vote
Accepted

Why is condition being ignored?

The problem is that the function get_pyramid_steps is never called by anything in main. It might as well not be there. If this answers your question, please click on the check mark. Let's keep up on ...
user avatar
  • 63.4k
1 vote
Accepted

Struggling with hash table! Pset5

new->word = dWord; I'd say that the address of dWord is being copied into the pointer(s) new->word for every node created, and not the actual word. When every word is processed, it is written ...
user avatar
  • 63.4k
1 vote
Accepted

pset3 find less comfortable if else expression result unused

There is no single thing called else if in the C language. The syntax of if is one of: if ( expression ) statement if ( expression ) statement else statement The construct if (condition1) ...
user avatar
1 vote
Accepted

Will the loop break in case the condition returns some value to the caller method in C?

"Will the loop break?" Technically speaking, no, it won't break. By using a return true statement, the entire function will immediately terminate and return a value of true to the calling code (or if ...
user avatar
  • 63.4k
1 vote

Will the loop break in case the condition returns some value to the caller method in C?

Yes, It will. By return keyword your program will be out of current function's scope. So it will be out of that loop.
user avatar
  • 158
1 vote

PS1 greedy question regarding formatting of do/while conditions

Do while behaves slightly different than while. You managed to find the exact difference :). Do while executes the code inside once and then checks your condition. That means in all cases the Do ...
user avatar
1 vote
Accepted

Week 1 - Conditions - error expression result unused (expect ; at end of if else)

The if/else if/else conditions are used in the following way: Single condition if (condition) { // code to execute } Double condition if (condition) { // code to execute } else { // ...
user avatar
  • 7,326
1 vote

Week 1 - Conditions - error expression result unused (expect ; at end of if else)

else is your last resort kind of command its like if this then { do this } or else if this then { do that } and finally when you cant think of any other condition you say you know what MR ...
user avatar

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