Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why I can't break while command here?

I am a newbie in coding. I am writing an online shopping code in C, I don’t know why but my code goes into an infinite loop and the scanf function in the block does not work. Even if I add if (b\<=a){break;}. My friend tried to run it on Linux and got a different result. It just writes "insufficient margin please add" several times depending on the input. Here’s my code;

int b = 100;
int add;
scanf("%d",&a);
while(a\<b)
{

    printf("unsiffcent margin please add");
    scanf("add%d",&add);
    a = a + add;
    }

I tried adding if(b\<=a){break;} but doesn’t work. I want a code that ask me too add to a number until number is greater than a value.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

scanf("%d",&add); will solve your problem

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading