Click here to Skip to main content
15,943,103 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
if i remove \n from scanf function then my code runs well and it doesnot ask for second input which has no role in it and and also when i enter 0 then it doesnot jumpto next line neither it stops the program but after giving 0 input again it stops the program so plz explain what \n is playing role here and what difference it created in program

What I have tried:

int main()
float testno=0,scoreentered,sum=0,avg;
printf("enter 0 to stopthe program\n");
    printf("testno:%f avg:%f\n",testno,avg);
    printf("enter score");

enter 0 to stopthe program
testno:0.000000 avg:0.000000
enter score1
testno:1.000000 avg:1.000000
enter score0
testno:2.000000 avg:2.000000
enter score0
~/workspace/ $ 
Updated 21-Feb-17 10:52am
[no name] 21-Feb-17 14:43pm    
Do you realize that we can't teach you programming over the internet don't you? Especially one question at a time when it's clear you have done no research at all before asking.
Member 13015247 21-Feb-17 14:46pm    
just answer the question dont give other suggestions if u have the sol give it otherwise keep shut
jeron1 21-Feb-17 15:06pm    
'u', 'sol', 'plz'? are two years old?
Member 13015247 21-Feb-17 15:23pm    
what do you want?first correct your english 'are two years old'.
[no name] 21-Feb-17 16:07pm    
I don't answer questions from abusive 10 year olds that can't be bothered to do the least bit of research before wasting everyone's time trying to teach you programming one question at a time.

1 solution

reading documentation and learning debugger is a good start to understand your programs.

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900