C++ FOR BEGINNERS (2025) - What is while loop, How to count digits of a number PROGRAMMING TUTORIAL

  Рет қаралды 33,526

CodeBeauty

CodeBeauty

Күн бұрын

Пікірлер: 91
@CodeBeauty
@CodeBeauty 4 жыл бұрын
📚 Learn how to solve problems and build projects with these Free E-Books ⬇️ C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook 🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/ Experience the power of practical learning, gain career-ready skills, and start building real applications! This is a step-by-step course designed to take you from beginner to expert in no time! 💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10). Use it quickly, because it will be available for a limited time. #include using namespace std; void main() { //Count digits of a number int number; cout > number; if (number == 0) cout 0)//0 { //number = number / 10; number /= 10; counter++;//3 } cout
@michellesanctuary9089
@michellesanctuary9089 3 жыл бұрын
we love your programming guide channel a lot 🍷🍹
@austinjohnathan4073
@austinjohnathan4073 4 жыл бұрын
I appreciate you making all of these. I've been learning C# for the last 6 or so months but recently discovered all of my comp sci classes will be using C++ exclusively. You making these videos will have a huge impact on getting up and running for my classes. As I said before, I really appreciate it. Please keep pumping these out!
@CodeBeauty
@CodeBeauty 4 жыл бұрын
Thanks Austin, I will! :D If you have any friends that could benefit from these videos, please share them, It really means the world to me and it helps me a lot to grow my channel!
@highboyy1346
@highboyy1346 2 жыл бұрын
hows college going now!
@bubblesbaby37
@bubblesbaby37 4 жыл бұрын
C++ also has abs() which will return the absolute value of a number. You can do number = abs(number) and get the same result.
@virx7944
@virx7944 3 жыл бұрын
For those that want to have greater than 10 Digits, change your data type from int number to long long number. I was able to get 19 digits from this data type.
@maysonsplay3972
@maysonsplay3972 4 жыл бұрын
I wrote in order to include minus numbers too like that: while (number > 0 || number < 0) :) It works:) Thank you for the lessons :) It helps me a lot :) I am still learning:) And I like your videos so much :D
@freshPrince0
@freshPrince0 2 жыл бұрын
what about while(number != 0) ?
@EmilianoGalati
@EmilianoGalati 2 жыл бұрын
@@freshPrince0 very clean and elegant! 👍
@jasonalba4004
@jasonalba4004 Жыл бұрын
I did the same thing
@saudalkhazriji4898
@saudalkhazriji4898 4 жыл бұрын
Before i even start watching the video i give you a like cause i know the video is going to be amazing👏
@IAmIshanSaxena
@IAmIshanSaxena 4 жыл бұрын
Yeah we need a video on debugging... and breakpoints
@Lafsha
@Lafsha 3 жыл бұрын
16:27 you should write long long instead of int variable
@kidzaki7201
@kidzaki7201 3 жыл бұрын
Thank you! Finally someone filled the "plot hole"
@Lafsha
@Lafsha 3 жыл бұрын
i have exam soon, i am using your tutorials thanks for your videos this is so helpfull for me , Good luck
@noperson-y6s
@noperson-y6s 3 ай бұрын
A little different variation int num; int digit = 1; cout > num; if(num < 0) { num = pow(num, 2); num = sqrt(num); } while(num / 10 >= 1){ num/=10; digit++; } cout
@findikbabi
@findikbabi 4 жыл бұрын
Yes, I would love to see a video about debugging. But I do feel like the code we wrote at 14:35 was unnecessary and made the code longer, so I just did this while(number>0 || number
@CodeBeauty
@CodeBeauty 4 жыл бұрын
👍Added debugging video to ma TODO list. You proposed a very interesting solution, and it is correct. The code below is going to work for counting digits of both positive and negative numbers! Well done! Excellent! int counter = 0; while (number!=0) { number /= 10; counter++; } Notice that I just converted your (number>0 || number
@subratadas9772
@subratadas9772 3 жыл бұрын
your explanation made understanding easy ,thanks.
@hajarelsayed20
@hajarelsayed20 3 жыл бұрын
THANK YOU SO MUCH I NEEDED THIS SO BADLY
@KanekiKen-gl8qo
@KanekiKen-gl8qo Жыл бұрын
I really just changed While(number>0) To While(number!=0) And worked properly
@CodeBeauty
@CodeBeauty Жыл бұрын
That's it
@maulanaajiw6184
@maulanaajiw6184 2 жыл бұрын
17:00 because you input 28 digit number, which is greater than integer maximum value
@thomaspfaff1074
@thomaspfaff1074 3 жыл бұрын
a other way of solution is: int number=0; cout > number; std::string s = std::to_string(number); cout
@tauchainagoras6044
@tauchainagoras6044 3 жыл бұрын
Hi, why do you use system ("pause>0"); instead of return=0; ? Thanks!
@xylianasky3652
@xylianasky3652 Жыл бұрын
same question I wanna know
@shamsyumar1194
@shamsyumar1194 2 жыл бұрын
Hey I find your programming vedios the most easiest ones, thanks and I really need a mentor like you please be my guardian. I what to learn C++ programming lang.
@benjaminavdic5631
@benjaminavdic5631 4 жыл бұрын
Pozdrav, obzirom da nisam bas za C++ svejedno se da nauciti a ucim vec druge programske jezike pa cu dati sansu da iskusam ovaj kanal. Dobila si novi sub
@rianvankessel3137
@rianvankessel3137 3 жыл бұрын
Yes make a video on debugging... and breakpoints, you're doing well.
@dandon.3667
@dandon.3667 Жыл бұрын
Thank you so much , you help me a lot .💙💙💙
@CodeBeauty
@CodeBeauty Жыл бұрын
I'm happy to hear that ❤️
@elsafernandatorresferia886
@elsafernandatorresferia886 3 жыл бұрын
Isn't it better to declare counter at the beginning and initialize it at the while loop? Is it the same thing?
@domus_k
@domus_k 4 жыл бұрын
Idk why but your voice is so therapeutic XD Thanks for teaching this, keep up the videos!!
@CodeBeauty
@CodeBeauty 4 жыл бұрын
I'm happy to hear that, thanks! 🥰🤗
@joe_joe_j035
@joe_joe_j035 3 жыл бұрын
How or could I use this same counter with a randomly generated number up to lets say 10 to tune it into a simple guessing game?
@Andy4Tune
@Andy4Tune 3 жыл бұрын
So, what happens when user types in 25 or more digit number, what is the solution?
@stefanskoric8046
@stefanskoric8046 4 жыл бұрын
Sorry i have a question. What if there is a situation where user enters decimal number? I fried my brain trying to make some kind of a solution but nothing crosses my mind from the stuff we covered until this video. Is solution beyond this level of knowledge? Everything else in this video is very much clear. Thanks.
@CodeBeauty
@CodeBeauty 4 жыл бұрын
The question that you're asking is a pretty complex one, and if you really are a beginner, then you probably will fry your brain trying to understand, so I'll try to explain as simple as I can. There is one fundamental problem with this question, and that is how will you know when you should stop counting?! In order to understand what I'm talking about, please try to execute this program #include #include using namespace std; void main() { float number = 123.1; number /= 10; std::cout
@adamheath8551
@adamheath8551 4 жыл бұрын
I think I found an alternative way to use negative numbers without the excess code or logic loops, what I did was for the while loop I put while(number != 0) and then the code, and that seems to work well, but perhaps doesn't work well elsewhere?\
@bubblesbaby37
@bubblesbaby37 4 жыл бұрын
did your solution include the negative sign in the digits count?
@sunflower9498
@sunflower9498 3 жыл бұрын
What happens in the even that the user enters a number with a zero in it? for example number 1024?
@40wattstudio41
@40wattstudio41 Жыл бұрын
Solved the > 10 number length problem by using type long long.
@CodeBeauty
@CodeBeauty Жыл бұрын
Yess 😃
@branriv8417
@branriv8417 3 жыл бұрын
So how we can count more than 10 digits if that is all and int can hold? Unsigned int? Also since a negative number can be divided by 10 couldn’t we simply change the while loop to execute as long as the number is != to 0 as opposed to > 1 instead of taking the absolute value?
@yummy9554
@yummy9554 2 жыл бұрын
#include using namespace std; int main() { int num; int counter = 0; cin >> num; while (num != 0) { num = num / 10; counter++; } cout
@benyaminshirani5824
@benyaminshirani5824 3 жыл бұрын
I was just wondering if You're actually a computer scientist or a model ;)
@AlvinKazaz
@AlvinKazaz Жыл бұрын
Dear Saldina, there is also another way to count digits beside 0 -> while(number !=0) { number /=10; counter++; }
@newprogramer7463
@newprogramer7463 3 жыл бұрын
I can do like that: while (number0) :) Thanks Saldina
@traianbadea7389
@traianbadea7389 4 жыл бұрын
Hi I want to ask if is an app C++for iPhone
@CodeBeauty
@CodeBeauty 4 жыл бұрын
You can write most of the IoS app in C++, but if you don't already have a lot of code that you just want to reuse and you are doing it from scratch, I'd say a better choice would be Swift or Objective C.
@manoharsagunthalla9215
@manoharsagunthalla9215 3 жыл бұрын
Dear Saldana zero too have value is’t? When entering 0 it should show you it contains one digit is in it? Suppose the user enters other than digit will it convert and tell the digits?
@creativescience1533
@creativescience1533 3 жыл бұрын
Help me one project Coil winding turn counting program Aurdiono based
@MegaWeixin
@MegaWeixin Жыл бұрын
Counter variable and while loop are automatically related?
@abdullahishehu7706
@abdullahishehu7706 2 жыл бұрын
please i did not understand from where did you get that value of 10
@mehranadimi9470
@mehranadimi9470 2 жыл бұрын
Thank you very much.
@fisherofmen489
@fisherofmen489 3 жыл бұрын
Woudnt it be more correct to state that the counter is really counting how many times the function can perform the operation(the act of dividing by 10), rather than saying that it's grabbing the last digit because it seems like that's what the modulo operation would do
@CodeBeauty
@CodeBeauty 3 жыл бұрын
Yep, correct ☺️☺️🤗
@kunalbatra4166
@kunalbatra4166 4 жыл бұрын
it can also be found using logarithms: floor(log10(number)) +1 except 0 obviously 😜
@CodeBeauty
@CodeBeauty 4 жыл бұрын
I haven't seen that solution before, but you definitely can come up with different ways to solve the same programming problem. I'm glad to see different ideas and approaches in the comments! 🤓
@thedeagle1007
@thedeagle1007 4 жыл бұрын
At 14:11 your solution to the negative number problem was inefficient in my opinion. I used an or logic gate in my while loop. Here's my code for the whole process here. *note I used n for number and c for counter. line 1 #include line 2 using namespace std; line 3 int main() line 4 { line 5 int n; line 6 int c = 0; line 7 cout > n; line 9 if (n == 0) line 10 { line 11 cout 0 || n < 0) line 16 { line 17 n /= 10; line 18 c++; line 19 } line 20 } line 21 cout
@vk2ig
@vk2ig 3 жыл бұрын
This statement cout
@thedeagle1007
@thedeagle1007 3 жыл бұрын
@@vk2ig thanks for the help!!
@subratadas9772
@subratadas9772 3 жыл бұрын
that line 15 is the acceptable as well
@subratadas9772
@subratadas9772 3 жыл бұрын
and thanks
@tumusiimebrian3745
@tumusiimebrian3745 4 жыл бұрын
Break points please 🙏🙏
@ivorperic297
@ivorperic297 3 жыл бұрын
Pozdrav, Zašto uopšte pišete dio u else{o množenju negativnog broja s -1} Je li se mogao while(number0) napisati ? Probao sam i meni lično radi pa ako možete molim Vas objasnite zašto taj korak sa else? Hvala :)
@mhdjaseem3195
@mhdjaseem3195 3 жыл бұрын
thanks, mam💕💖
@clarrisac750
@clarrisac750 4 жыл бұрын
Thanks CodeBeauty🤩 Even as a slow learner,I am able to catch up with ur videos. Hope you can include exercises to try at the end of video, just a suggestion from me hehe.
@CodeBeauty
@CodeBeauty 4 жыл бұрын
That is a good suggestion. Sometimes throughout the videos I give you tips on how you can improve and upgrade programs that we build, but I'm also going to try and include exercises at the end whenever possible. :D
@eonisplaying
@eonisplaying 3 жыл бұрын
Just put the condition while (number!=0) Thanks.
@MetaVaria
@MetaVaria 4 ай бұрын
I didn't need to turn my negative number into a positive one to work. I did this: while (number > 0 || number < 0)
@tirushsanju2917
@tirushsanju2917 3 жыл бұрын
How we can enter more than 10digit number ??🤔
@rameenbabar3155
@rameenbabar3155 4 ай бұрын
i want to clear something that when i'm intentionally trying to overflow my code i am not getting 10 digits instead my code says contains 9 digits #include using namespace std; int main() { int number; cout > number; if (number == 0) cout
@husseinmahmoud7216
@husseinmahmoud7216 3 жыл бұрын
For the last situation you did not say what the solution was ?
@IrisFlorentinaA
@IrisFlorentinaA 3 жыл бұрын
i did exactly as you showed but my program wont compile. i enter nr 12 ,and it takes a LOT of time to get the result ...it "eats" a lot of memory and my laptop fan makes a lot of noise EDIT :: MY MISTAKE :))) i wrote while (nr > 0) { nr == nr / 10; OMGGGGGGGG
@MirkoBjelica
@MirkoBjelica 4 жыл бұрын
Notice how she wasn't sure if -335 will work after adding abs part of the code and she switched to -236. Foxy Lady! :)
@everydaymachi1047
@everydaymachi1047 3 жыл бұрын
it seems like people lack motivation because as the course goes on the number of views are deceasing hugely .
@cuol5675
@cuol5675 3 жыл бұрын
omg the headlice trying to understand the code 😵🤯
@cuol5675
@cuol5675 3 жыл бұрын
haha after your expiation i got super relived omg it was so confusing trying to understand it by yourself...
@ВилианПопов
@ВилианПопов 3 жыл бұрын
int number; cout > number; if (number == 0) { cout
@Roman-L
@Roman-L 4 жыл бұрын
Who else noticed that Windows taskbar is at the same level as her desk :D sooo satisfying :DDDD
@arioirandoost5265
@arioirandoost5265 2 жыл бұрын
10
@imnot9923
@imnot9923 2 жыл бұрын
Comment for Algor
@apnagaon3334
@apnagaon3334 2 жыл бұрын
Ma'am, can U please provide me a valid questions related to the C++ And I've send U a connection on LinkedIn...... If You have a.... Then plz send me a question
you will never ask about pointers again after watching this video
8:03
人是不能做到吗?#火影忍者 #家人  #佐助
00:20
火影忍者一家
Рет қаралды 20 МЛН
Count The Digits In An Integer Using Recursion | C++ Example
5:14
Portfolio Courses
Рет қаралды 2 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 839 М.
Learn Any Programming Language In 3 Hours!
22:37
Code With Huw
Рет қаралды 605 М.