C objective something wrong with if statement [closed] - c

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
This code written in c objective with Visual Studio
Today a friend of mine sent this code. In university they tried to make a grade calculation program. The problem is when you write -0 to input and press enter it gives result as the last if statement regardless the if statement is.
Same conclusion appears when you write +0 etc.
Why this is happening any ideas? Thanks in advance.

The concept of negative zero doesn't exist in the C language (and all other languages I'm aware of).
So if you enter 0, the expression grade == -0 will be true and therefore your program will display Zero can not be negative.

Related

Why doesn't assert do anything? What do I need to do to get it to work? [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have experienced a strange problem when using assert in my program.
The program does not terminate even when I add a line of codeassert(false).
But the assert works when I write several lines of sample code. Anybody know why it happened?
If you have:
#define NDEBUG
this turns all assert's into nop's.
If you have differing behaviour, depending on the amount of code, then I guess you don't have NDEBUG defined and I would guess the compiler is simply compiling out the redundant code.
More details about environment are required, however, you give a definitive answer.

Mysterious extra text in style check [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am working on CS50's Runoff problem in Problem Set 3, and the program is working when I run it. When I run the check program, however, it notes one particular function as being wrong entirely despite it working when I run the program manually. When I run the style check program to make sure there is no excess whitespace, etc; the results show extra text where there is none in the program.
In both of the screenshots I have the function returning the error in the top window.
Any ideas what is causing the mystery text, or the 4 errors? If it s more helpful, I can paste the entirety of the code here.
Thank you!
Do not be distracted by style50. Any style issues should never change the results of the program. The program is failing check50 because of functional deficiencies. The spec for print_winner says:
If any candidate has more than half of the vote, their name should be printed to stdout and the function should return true.
"More than half the vote" depends on the number of voters not the number of candidates. Try an election with 3 candidates a, b, c with 7 voters who vote b,b,b,b,a,a,c. Who wins? (b). What result does program return?
Deal with style issues after program passes check50 and before submit50. (But it's good practice to double check check50 results after cleaning up style, lest a bug creep in :)

Count amount of words, characters, newlines in C [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I know it is not recommended to post code as an image, since I am getting a formatting error when trying to post code on here. Anyway, I am trying to write a simple C program to count number of words, characters, newlines using do while loop. However, the output is not as expected. Please help!
Instead of a do-while, you should try using while. Since your code starts off by checking whether a is any of your if cases, it goes to the else case, and increments the New line variable. If possible, could you share the output screen.

WhY in C programming ,perc value show 0 as output? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
perc=(sum/total)*100;
i've been trying to put this in the code in cprogramming,but output for this part is showing 0,,,Why is this happening and what else should I do in these types of scenerios?
Since you didnt post source and this question will be closed soon, the cause is from integer division most likely. Try this instead.
float perc = ((float)sum / (float)total) * 100.0;
Heres a post on integer division if you are interested in learning why this behavior is doing what it did:
What is the behavior of integer division?

Converting a character into a space in C arrays [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
So lets say I have received a message that resembles the following
"L2N5*8R10!11T0A1K3Y14#4W7O6O9C12R13"
and I am expected to sort out the characters in accordance to the numbers succeeding them and change the characters that are not letters into a space. I have no problem doing the sorting out part, I am only having a trouble while trying to write a function that will change those characters into space.
The out put should be something like this
TALK NOW OR CRY
but I am getting
TALK#NOW*OR!CRY
Can anyone help me figure out what my function should look like so that I can be able to change the characters into space??
Unless you show your code, we'll only be able to guess!!
However, as a general suggestion, I would recommended, you should check each entry against isalpha(). In case you got a return value of 0, replace the entry with a .

Resources