Hot answers tagged

2

The main problem is in the following statements: string answer = 0; answer[i]= min_value; Let's see if I can explain it clearly; a variable of type string is really a typedef (an alias in other words) of char *, that is, a pointer to a char, the first of the previous statements assigns a null (zero) pointer to answer, the second statement tries to ...


1

In the for loop use, (i = n, i >= 0, i--). This will start from n and go to zero so the output is in descending order. Hope this helps. If it does, please check the tickmark.


1

The code is supposed to keep prompting for a new value until the user enters an acceptable number. This code doesn't do that. Instead, it will ask for a number, and if that number is out of range, it will skip down to the end of the program where it will ask for a new number a second time, but it won't do anything with it. When the second number is ...


1

Maybe you're just overthinking it a little? ;-) Just move the printf(Success) statement below the for loop. If the test fails, it's going to exit through the return statement. Otherwise, the code has to drop out of the loop, at which point it must have passedm so that's when you print a success message. If this answers your question, please click on the ...


1

So after you get an error message that says "Out of Range", when you try to enter another value that is out of range, the loop stops. There is a "clearKeyboard()" function that is called in here - this is to clear the buffer of the "\n" character as it creates problems for strings in C using scanf. After struggling with this for a good while, I thought ...


1

It's actually in a loop that prints the first initial that follows a space. You can test this by entering 3 names instead of 2, like david willima smith. It would repeat w's infinitely. The problem lies in your while and for loops. They are both controlled by the counter var i. Let's ignore the printf statements for now. The while loop starts, goes into ...


1

The previous answer points you some mistakes, you should correct them. But your major conceptual problem is here: if (isspace(name[i]) == true && .....) it does not work like that. isspace() by itself return true or false, you do NOT need to compare it with true or false. It is the same mess as if you would do like that: if((n > 1) == true) ...


1

Problem with the while version here: while (i <= 1 && i<=n). It will execute the loop exactly once. After i++, i is 2, and i <= 1 is false, loop over. (I think there's a problem with i<=n too, since that will test an invalid index here name[i+1] != '\0') As for the for loop, I wouldn't say redundant exactly. Since it is incrementing i ...


1

A quick way to format code properly: select the code and click the {} in the format bar, to-da. This can be done on initial post or you can edit the question and fix the format. Here is the pseudo code from the walkthrough: psuedocode: "recopy" method for each row      for n-1 times      &...


1

infile is a string, it's content is the expression "card.raw". So what exactly is this loop supposed to accomplish? for (int i = 0; i < *infile; i++)


1

Rob was demonstrating the use of a for loop to load values into an array. The i doesn't stand for anything. It is simply a counter for the for loop. It is a standard and common practice to use a single letter, and most commonly, i as a counter in for loops like this. the array ages[] has 4 elements, numbered 0 to 3. In the for loop, i is incremented from 0 ...


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