C Programming Tutorial – 26 – do while Loops

Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts

Comments

Dirasa Dirasa says:

this program does not make sense , it should have better example

Zhihao Guo says:

What if someone really got 0? LOL

mehmet sahin says:

First time he did a fail about programming.He wrote print :)

shizyninjarocks says:

Very good explanation.

jlbgalang says:

is this possible with an if statement inside the loop? i cant make it work…

amr makhlouf says:

Ty very much

Shimada - Squad says:

i made a software that calculates the average of pumpkins sold per deal . microsoft hold on i’m coming :p
IN case some one wants to steal my idea and become rich :
#include
#include
int main()
{
float pumpkinssoldeverytime=0;
float numberofdeals=0;
float totalpumpkinssold=0;
float averageperdeal=0;
printf(“please press 0 when completen”);
do{printf(“number of deals: %.0f t total pumpkins sold: %.0f t average per deal: %.2fn”,numberofdeals,totalpumpkinssold,averageperdeal);
printf(“how many pumpking you sold this time ?n”);
scanf(“%f”,&pumpkinssoldeverytime);
numberofdeals++;
totalpumpkinssold+=pumpkinssoldeverytime;
averageperdeal=totalpumpkinssold/numberofdeals;
}while(pumpkinssoldeverytime!=0);

return 0;
}

MJ Sanchez says:

The text is too small.
Somebody goofed up.

True entertainer says:

FOOD LOVER
int main()
{

int aalotikki = 25;
float days = 0;
int procost = 10;
float aalosales = 0;
float sales;

printf(“TYPE ‘0’ WHEN COMPLETED nn”);

do{
printf(“DAY=%.0f t BURGERSALE=%.0f n”, days, aalosales);

printf(“ENTER THE AMOUNT OF BURGER SOLD TODAY? n”);
scanf(” %f”, &sales);
days++;
aalosales = (aalotikki – procost) * sales;

}while(sales != 0);

return 0;

}

Goldy Bhatia says:

Your tutorials are awesome but you should increase the font size from next time

Brian Kiprono says:

Good execution of the joke made it even funnier

NotAnyTrap says:

guys, i typed in the 16th line scanf(“%.0f”, &scoreentered); and thanks to that my program kinda wasn’t working ( please try this )
can i know why?

AJay Gupta says:

why you are using “grade” in this program. instead use total

billy HH says:

Hey just wondering how you do an if else in this to assign for example 90 as highest

CFREE says:

I know the grade you have to declare zero but why do you declare the other variables zero?
Can anyone help?

XTGreatShowsce says:

i thin you can do this without do while , just use if (answer== 0) { } ;

Na Li says:

A great tutorial! A question:
scanf() line: instead of scanf(” %f”, “ScoreEntered”); I wrote scanf( ” %.2f”, “ScoreEntered”). The program only run once. What makes difference between %f and %.2f here?

Thanks

Namless Gamez says:

yo, umm, i was trying out this code, but everytime i enter a number, my PC crashes, can someone run this in their computer and see if it is just cuz my pc i slow

int main()
{
float overall = 0;
float entered = 0;
float times = 0;
float avg = 0;

printf(“AVERAGE CALULATORnnpress 0 when completenn”);
do{
printf(“current average: %.2fnn”, avg);
printf(“input number: “);
scanf(“%f”, entered);
overall += entered;
times++;
avg = overall / times;

}while(entered != 0);

return 0;
}

Alex Peretti says:

I am trying to practice more “the do while loops” and I came across to this:
Can I use characters (char) to test in a WHILE? or only numbers? I would like to create a program that requests the user to enter a name (predefined) and while this name is not typed the program will keep asking to enter the correct the name. I hope this make sense :)

It didn’t work:

int main()
{
char name;

printf(“Once you have typed the correct name the program will stop!n”);

do {
printf(“What is the correct name?”, name);
scanf(” %c”, &name);
}while (name != ‘alex’);
return 0;
}

mehmet sahin says:

float tutar = 0;
float ortalama = 0;
float alisverissayisi = 0;
float marketegidis = 0;

printf(“Cikmak istediginizde 0’a basin nn”);
do{
printf(“Markete Gidis : %.0f OrtalamaTutar: %2.fn”, marketegidis , ortalama);
printf(“nAlisveris Tutarini giriniz :”);
scanf( “%f”, &tutar);
alisverissayisi += tutar;
marketegidis++;
ortalama =alisverissayisi / marketegidis;

}while (tutar != 0);{
if (tutar == 0){
printf(“Alisveris bitti”);
}
}

Darky Games says:

Dude I’m So confused About Do while loop..You r good..but u used too much Floats ha ha that’s Blow my mind..I think I can understand After watching 3-5 times…Keep it up bro nice tutorials

john paul reyes says:

hi guys, can someone give me an assignment with loops to practice, heres my gmail. starscreamscreamo111@gmail.com
please i really want to improve my coding skills..

Asad Siddiqui says:

epic..

kyriacos h says:

how can i compare a string? for example
#include
#include

int main()
{
char cmd;

printf(“Welcome! n”);

do{

printf(“COMMAND>”);
scanf(“%c”, &cmd);

}while(cmd != “EXIT”);

return 0;
}

i know i cannot do it because c recognize this as addresses.
i have tried some things in stack overflow with no results.
How can i compare the cmd string to not be EXIT in order to repeat?
and when EXIT then exit? please help

Nomade says:

Bucky, What if my score is 0 p;

Michal Pitr says:

It demonstrates the Do while loop well, but I wouldn’t choose 0 as the quit command since you can score 0

Me Qayim says:

This too

Raja Kishore Mohanty says:

nyc video

Shadow Meth says:

It’s not a bad programming practice if we leave the false condition code area empty in the shorthand if statement right?
#include
#include

int main()
{
float grade = 0;
float scoreEntered = 0;
float numberOfTests = 0;
float average = 0;
printf(“Press 0 when complete. nn”);

while(true){
printf(“Test:%0fttAverage:%.2f n”, numberOfTests, average);
printf(“nEnter test score: “);
scanf(” %f”, &scoreEntered);
(scoreEntered == 0) ? break : ;
grade += scoreEntered;
numberOfTests++;
average = grade / numberOfTests;
}

return 0;
}

Ahmet Leone Popaj says:

how does it work?

yerrapotu kiran says:

Thank you Bucky

cornelxbox25 says:

I wrote my floats like so: float grade, scoreEntered, numberOfTests, average = 0;

Umar Aqim says:

#include

int main()
{ int x = 1;
char y, Y, c;

do{
printf(“Current number %d”, x*2);
printf(“n”);
printf(“Continue? “);
scanf(“%c”, &c);
printf(“n”);
x++;
}while(c!=y || c!=Y);

return 0;
}

Hey can you check my code here? its supposed to stopped when i press other than y/Y.. but then its keep on looping regardless on what character i entered..

Complexity says:

It would be better if it were zoomed in.

Francisco José Olivero says:

You could do this same program without a do while, and just using a while, is this correct?

Jimmy Botsko says:

How did you make it so when you clicked a variable, all of that variable was highlighted???

Mr. J_Krr_ says:

what have you done now these parents are just gonna know all those dirty little secrets we hide behind those averages…. T_T

Dari Acuña says:

Sucks for the student who got 0 on the first test.

Sebastian Dark says:

error: 1d returned 1 exit status :(

Shihabur Rahman says:

I think this can be done with using just while loop?

HabelFoc _ says:

This is make sense? let me know guys or any better code let me know

#include
#include

Spoder Moan says:

hey Bucky , how your program will run if someone had zero at test ?

Dilantha Perera says:

Cool

UnboxModz says:

overflow info: type AAAAAAAAAAAAAAA lol

Gabe Morris says:

whats the point of the do part? why not just start off with the while (scoreEntered != 0) and get rid of the do part all together?

Benjamin de Montgomery says:

Why are these videos replaced by other C# videos with relay shitty sound? These are great. how can i watch just your videos Bucky?

Camp OpenSource says:

Substitute C for 0 as the user will undoubtedly enter 0 as a score if they missed a test.

Seamaro. says:

Could anyone tell me why you would pick a certain loop over another one? for example why would you pick a do loop over a while or for loop? thanks!

Write a comment

*

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles   Show Cars   Motorbikes   Scooters   Rims & Tires   Luxury BoatsFashion   Sunglasses   Luxury Watches   Luxury Purses   Jeans Wear   High Heels   Perfumes   Jewellery   Cosmetics   Shaving Helpers   Fashion HatsFooding   Chef Club   Fooding Helpers   Coktails & LiquorsSports   Sport Shoes   Fitness & Detox   Golf Gear   Racquets   Diving Equipment   Ski Gear   Snowboards   Surf Boards   Rollers & SkatesEntertainment   DIY Guides   Zik Instruments   Published Books   Music Albums   Cine Movies   Trading Helpers   Make Money   Fishing Equipment   Paintball Supplies   Trading Card Games   Telescopes   Knives   VapesHigh Tech   Flat Screens   Tech Devices   Camera Lenses   Printers   USB Devices   PC Hardware   Network Gear   Cloud Servers   Software Helpers   Programmer Helpers   Mobile Apps   Hearing AidsHome   Home Furniture   Home Appliances   Beddings   Floor Layings   Barbecues   Aquarium Gear   Safe Boxes   Office Supplies   Security Locks   Cleaning ProductsKids   Baby Strollers   Child Car Seats   Remote ControlledTravel   Luggages & Bags   Airlines Seats   Hotel Rooms   Fun Trips   Cruise Ships   Mexico Tours