C Programming Tutorial – 6 – While Loops

Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –






49 responses to “C Programming Tutorial – 6 – While Loops”

  1. Marco André Schmidt Avatar

    Thanks, very helpfull god blles

  2. Ng WS Avatar

    Sir how to reset the counter variable to its value?? Because after the loop the counter variable will be store as 5 …. I have this problem in my code … I need to reset the variable back to its original value again

  3. Zoya Khan Avatar

    i need c compiler can any one help me

  4. amandeep Avatar

    bit more detailed

    #include <stdio.h>
    int main()
    int days,lc,hotdog,total,average;
    printf("enter the total number of days");
    printf("enter the number of hotdogs ate on day%d n",lc);
    printf("hotdog u ate are %dn average=%d",total,average);

    return 0;

  5. Issac Wiggins Avatar

    When using int main() does there have to be void in there? Or is that suppose to be the name of the program you are using?

  6. Niko surya pratama Avatar

    nice explained. i got question, so i have some code that in while loop there are for loop. when i run the program the looping working just fine but when the condition of while loop already fulfilled, it cant exit the loop. did u know what is the problem?

  7. TheMoony3455 Avatar

    I loved your video, i'm just starting with C language and it was hard for me to understand it but your way of teaching is great, so thank you 🙂

  8. ravy pmr Avatar

    hey can't i just use loopcount++ for incrementation instead of loopcount+1?

  9. Wesley Teoh Avatar

    Would it be different if I write:"

    int loopcount= 0;
    int hotdogs;
    int total= 0;
    int average;?


  10. Anish Raj Avatar

    which compiler is this?

  11. rayray123ray69 Avatar

    I love your vids, learning so much! I noticed in this one that the line at the end says total, but it's displaying average, so i wrote an extra line to get both total and average:
    printf("total number of dogs was %d n", total);
    printf("average number of dogs was %d", average);

  12. dragan zica Avatar

    int main(void)
    float average,total;
    int loopcount,hotdogs;

    printf("Enter number of dogs ate:");
    printf("nAvrage number of dogs ate was %f",average);

    (if you wana for program to give a perfect resoult)

  13. le00 Avatar

    so glad i learned javascript first 😀

  14. Paul Klein Avatar

    my teacher said that you must always use float for average. why did you put average in int? what is the effect of that?

  15. S.Pheakdey Arn Avatar

    I wonder that the total number of ur example was wrong 🙁 Why the total is 17;
    i define why 2+4+54+22+6 = 17  . If you say it 17 average wyy (2+4+54+22+6)/5 = 17 ; of course it is 15.6 . 
    Sorry . Would u explain by replying , plz ???

  16. SillyCoder Avatar

    who can eat 54 hotdogs a day. You must be crazy! 😀 Btw, you are funny. 😀

  17. Affina Jamal Avatar

    hey, i wanna ask how to program showing how much positive/negative/zero number when its required to have 5 inputs.
     eg; 2, 5,10, 0, -8 
    so the answer would be
    there are 3 positive, 1 negative, and 1 zero number
    i'm still new with programming please teach 🙁 the looping i understand but to choose and list how much, idk how. please do tell me! thank you!

  18. nhom kenfreeze Avatar

    What is ur website? 

  19. Sandy Telfer Avatar

    how would i write code to incorporate a running average?

  20. Antony Sbeghen Avatar

    I was able to learn at my own pace and include a few more lines of code. 🙂


    #include <stdio.h>

    int main(void)
    /* Variables */
    int numOfTotalDays;
    int numOfDays;
    int numOfHotdogs;
    int numTotal;
    int numAverage;
    int loopStep;

    loopStep = 0;
    numTotal = 0;

    printf("Please enter the amount of days the contest is held: ");
    scanf("%d", &numOfDays);

    while(loopStep < numOfDays)
    printf("nPlease enter how many hotdogs were eaten on Day %d: ", loopStep + 1);
    numTotal = numTotal + numOfHotdogs;
    loopStep = loopStep + 1;

    numAverage = numTotal / numOfDays;
    printf("nnThe average number of hotdogs that you will eat is %d", numAverage);

  21. krutomjer Avatar

    This works in Xcode without <conio.h>, and it gives decimal values (float)
    #include <stdio.h>

    int main (void){
        int loopcount;
        int hotdogs;
        double total;
        double average;
        loopcount = 0;
        while (loopcount<2){
            printf("What is the nuber of hotdogs eatenn");
            total= total + hotdogs;
            loopcount = loopcount+1;
        average = total/2;
        printf("You've eaten %f daily n", average);

  22. daniel nwabueze Avatar

    good but we student should  always remember to use float for calculating average in an exam or quiz. making a mistake like that is huge 

  23. Roark Zhang Avatar

    For the variables, you can just add commas between them.

    Int loopcount, hotdogs, total, average;

  24. MrHaloman95 Avatar

    # include <conio.h> for some reason doesn't work with Xcode is it conditional marcos instead?

  25. Garrett Carlson Avatar

    Just to be a stickler, the total number of dogs would be the final value of "total" as you added up the hot dogs.

    As you explained, you calculated the average daily hot dog consumption over the period of five days, but then your program says that the "Total number of dogs was…" the average number of dogs, which confused me near the end.

    It was especially confusing because I've never heard of a hot dog eating contest that takes place over a five day period, so I didn't understand why we were entering different numbers of hot dogs each time. This seems more like a diet program to me. If we replace "hot dogs" with "calories" and enter that on a daily basis we can calculate our average calorie intake on a daily basis.

    Thank you so much for your series of tutorials. You can't satisfy everyone, but this is stuff people pay hundreds of dollars to learn in a college, and that's satisfactory enough.

    Society needs to start recognizing the potential in this kind of education instead of forcing everyone to spend money they don't have for a degree they shouldn't need, because people with degrees aren't necessarily experts, and experts don't necessarily have degrees, but they sure do earn their rights to apply their knowledge. Our system is so back-asswards.

  26. Slidey Sims Avatar

    #include <stdio.h>
    #include <conio.h>

    int main(void){
        int count;
        int x;
        int sum;
        float mean;
        int datapoints;
        sum = 0;
        count = 0;
        printf("Enter number of datapoints to average: ");
        scanf("%d", &datapoints);
        while(count < datapoints){
                     printf("Enter data: ");
                     scanf("%d", &x);
                     sum = sum + x;
                     count = count + 1;
        mean = sum/datapoints;
        printf("The mean is %d", &mean);

    I always get the mean to be 2293560. I hope someone can point out the error in the code.

  27. Zelkathz Avatar

    I think the loop will run for only 4 times? cuz (loop<5). 5 unless, (loop<=5) ?

  28. clanwargods Avatar

    You don't know how much I love you right now. Thank you Bucky!!! >____<

  29. Mohammed Hossam labretso Avatar

    Can,t i just write int loopcount = 0; as in java?

  30. Southern Cal Sands Avatar

    your teaching style rocks, thank you!

  31. Shohag Ahmed Avatar

    my code give the same answer (2686736) everytime

    int main()
        int loopcount;
        int hotdogs;
        int total;
        int avarage;

        while (loopcount<5){
            printf ("Enter the number of hotdog you ate:");
            scanf ("%d", &hotdogs);
            total= total + hotdogs;
            avarage = total/5;
                printf ("The avarage number of hot dogs you ate is: %d"), avarage ;
        getch ();

  32. aayushrjl Avatar

     when i compile this program it shows( warning"function should have a return value")

  33. Haripazha Aezakmi Avatar

    it this also working? for (loopcount=0;loopcount<5;loopcount++); ?

  34. abdikhani abdi Avatar

    thanks for the tutorial !

  35. Rishmita Rao Avatar

    can you execute the code if the statement is not true?

  36. Nina girl Avatar

    Hi Bucky, thank you for all your videos you are propably the best :). so I have a problem!!! when I write  a small cod for exemple ("hello word") etc  my Dev++  compiles but when i write serveral codes   like for "While loops" it does'nt work ): so please can you tell me where is the problem?  thank you 

  37. Mobius Avatar

    printf("total number of hotdogs eaten: ", total);
    printf("average number of hotdogs eaten: ", average);

  38. Raghav .Y Avatar

    he used it in C Programming Tutorial – 7

  39. Greg Lynch Avatar

    it means console input, output

  40. anthony Bal Avatar

    What is #include conio.h

  41. Marqkita Sexton Avatar

    Thank you so much for you helpful tutorials. I'm taking C Programming this semester and my professor has a hard time relating the info to us. I wish you were my teacher because I hate this class.

  42. Alaa Nemet Roel Avatar

    you are amazinggggggggggggg

  43. metalbuttons Avatar

    so is loopcount the number of days?

  44. Adelin Nedelcu Avatar

    the result is an integer, that's why.

Leave a Reply

Your email address will not be published. Required fields are marked *