Buckys C++ Programming Tutorials - 20 - Sentinel Controlled Program

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии • 456

  • @musicignited2725
    @musicignited2725 8 лет назад +179

    Dude, I swear you have a way of teaching C++ so simply and understandable! I take 45 mins of CS class and I'm still left in confusion on certain topics, thank you so much for investing your time to do these tutorials!

    • @beri4138
      @beri4138 7 лет назад

      Just curious but does learning C++ help with CS?

    • @lich.possum
      @lich.possum 4 года назад +1

      @@beri4138 the idea is that if you can learn c++ the lowest level language you can learn higher level languages

    • @Hvidbergen
      @Hvidbergen 4 года назад

      @@lich.possum where do you get that idea from? And what do you mean by "lowest level language"?

  • @samirgunic
    @samirgunic 9 лет назад +71

    Just to clarify one thing: the "sentinel" is the "-1" value itself. It's called a sentinel value. It's a special value that controls when to terminate a program, or as in this example: when to step out of the loop. It just so happens that in this example the program ends once he steps out of the loop. But other programs could do other things after this. Hence, "sentinel controlled program". It's not a program controlled by a certain Sci-Fi character if you know what I mean! ;-)

    • @GizziMoD
      @GizziMoD 8 лет назад +4

      +Samir Gunic thx.. I was wondering just this! :)

    • @nerdii1842
      @nerdii1842 3 года назад

      oh cool, thanks for explaining that.

    • @hetaeramancer
      @hetaeramancer 2 года назад

      sentinel vs scourge yun pare

    • @hetaeramancer
      @hetaeramancer 2 года назад

      " a program controlled by a certain Sci-Fi character if you know what I mean! ;-) "
      dude, seriously? a sentinel controlled program is when a sentinel value controls it. quit messing around and talking about sci-fi characters bro. not cool

    • @samirgunic
      @samirgunic 2 года назад +1

      @@hetaeramancer no way?! You need to get a sense of humor. Relax, we are not in school here.

  • @sicklaxplayaz
    @sicklaxplayaz 13 лет назад +1

    I've noticed a great way to test if you actually learned anything from Bucky's tutorial. Always try to make a program similar to the one that you just made in the tutorial, if you are struggling, go back and watch the tutorial again. This has worked for me, and i just wanted to share it with you.

  • @chrismavian6194
    @chrismavian6194 11 лет назад +2

    I like how he makes everything sound so easy. Something to definitely work towards.

  • @widowdev
    @widowdev 6 лет назад +2

    Hey Man. I know this was posted in 2011, and I don't even know if you are active on this channel or not.. but this is really enjoyable to watch. I am taking a condensed 6 week online C++ class at Penn State and yes the book we use is extremely good, but having you think through an example and explain everything is really helpful. I don't have a professor doing that like I normally would in a class like this, all I have is worked out examples in the book - so this gives me that feeling of having a professor to teach me it. Thanks a lot man, appreciate this.

  • @DeejayAlid
    @DeejayAlid 7 лет назад +21

    Nice tutorial, it would have been great if you gave us exercises at the end of each video, thanks for the tutorials.

    • @theseangle
      @theseangle 4 года назад

      @Sourin 2 🤦‍♂️

  • @RCTestKid
    @RCTestKid 9 лет назад +12

    Woot. Have watched 20 of your C++ tutorials in 2 days! Aiming to watch 10 a day until I have finished your series!

    • @lastofthestars6481
      @lastofthestars6481 6 лет назад

      Really ??

    • @reshavraj4090
      @reshavraj4090 4 года назад +1

      Mee to @zak

    • @RCTestKid
      @RCTestKid 4 года назад +1

      @@reshavraj4090 Awesome! (yes I did finish the series)

    • @reshavraj4090
      @reshavraj4090 4 года назад +1

      @@RCTestKid Any suggestions..for data str and algo.!!

    • @RCTestKid
      @RCTestKid 4 года назад +1

      @@reshavraj4090 Sorry, I don't know what you're asking.

  • @muhdsafwan401
    @muhdsafwan401 8 лет назад +73

    cout

    • @kiva8986
      @kiva8986 7 лет назад +7

      #include
      using namespace std:
      main()
      {
      int myAge;
      cin >> myAge;
      if (myAge > 1) {
      cout

    • @zakariaosman6487
      @zakariaosman6487 6 лет назад +1

      its using namespace std;
      and int main()

    • @yaboi3749
      @yaboi3749 5 лет назад

      *RETURN 0;*

    • @grossio5564
      @grossio5564 4 года назад

      @@yaboi3749 yeah you are right........ YA BOI

  • @onelerv1
    @onelerv1 13 лет назад +4

    I wish I could subscribe more then once to this channel.. I'm so grateful to bucky, he's taking up his own time to help out with teaching us.. Thanks man I really appreciate all your help!

  • @WhosTheBossHD
    @WhosTheBossHD 9 лет назад +10

    Here's a common practice every coder MUST know. Whenever, you have a variable as your denominator, it is a good idea to make sure that your variable is not 0 (Zero)

    • @Nightcrawler9001
      @Nightcrawler9001 9 лет назад

      WhosTheBossHD but if he didn't make total age 0 than it would've been null and u cant add to null

    • @abird35
      @abird35 9 лет назад +3

      +KomodoPanther what he means is that he should've probably added an if (NumberOfPeopleEntered != 0) statement over cout

    • @CaliforniaGuys916
      @CaliforniaGuys916 9 лет назад +1

      This is a very good tip, and I actually ran into this problem while I was in class and couldn't figure out what was going on.

    • @hetaeramancer
      @hetaeramancer 3 года назад

      how the hell could it be 0 though? idiot...

    • @user-vv9fw7ok9d
      @user-vv9fw7ok9d 3 года назад

      @@hetaeramancer Understand what he is saying before insulting him! In case the first input is -1 then the program terminates with numberOfPeopleEntered = 0. Now I wonder who is the idiot...

  • @TakingItCasual
    @TakingItCasual 13 лет назад

    I was tinkering with the last tutorial and made something that allowed the user to decide how many numbers they wanted involved, but this looks like it gives more options. Time wasted, lessons learned. Love your videos!

  • @carlgauss8879
    @carlgauss8879 8 лет назад

    And on Bucky's 20th tutorial, I finally found out about AD Block Plus for RUclips's beyond obnoxious amount of ads. Life is beyond amazing.

  • @miguelmartinez1607
    @miguelmartinez1607 Год назад

    11 Years Later and still the best tutorials! Thank you! Also would have taken this opportunity to teach ageTotal+=age; instead of ageTotal = ageTotal +age;

  • @shyamsrinivassportive9182
    @shyamsrinivassportive9182 2 года назад

    Man, what are you? You are teaching way more better than many paid tutors. You deserve more than this

  • @NA-is2oo
    @NA-is2oo 7 лет назад

    your 360p quality recorder is actually so satisfying like everytime i switch back to the video after i finished a line of code you demonstrated.
    im actually happy

  • @SetYourHandle3
    @SetYourHandle3 9 лет назад +1

    I love all your work Bucky. Thank you for making these tutorials :).

  • @RoxusRemo
    @RoxusRemo 8 лет назад +13

    guys keep clicking onto each concurrent video every second and you get a really cool mix of "hows it goin guys"

    • @zeustheboerboel3794
      @zeustheboerboel3794 8 лет назад

      ads!!

    • @Ele20002
      @Ele20002 8 лет назад +2

      adblock!!

    • @hbv8560
      @hbv8560 8 лет назад +11

      Don't use adblock on his vids, this is his income...

    • @felixruiter3354
      @felixruiter3354 2 года назад

      This was much more entertaining than I thought it'd be

  • @emmanuelhjg69
    @emmanuelhjg69 13 лет назад +2

    When you declare your variables, always set it to 0 because it can get random values if you don't

  • @blazingredgaming7377
    @blazingredgaming7377 11 лет назад +34

    int numberOfPeopleEntered
    can be shortened to
    int nope

    • @george18almonte
      @george18almonte 6 лет назад

      I put numberOPE

    • @coows
      @coows 6 лет назад

      You mean string numberOfPeopleEntered = "nope"
      Because you can put words into int, but it's better to put it into a boolean or a string. Really, it's that simple. Try subtracting int "1" and boolean "1" and it wont work. (boolean for short is bo)

  • @NALDstudio
    @NALDstudio 11 лет назад

    None of our suggestions is wrong actually. Both are very simple to type and to understand.

  • @PapoochCZ
    @PapoochCZ 11 лет назад

    You can set a new variable to any number if you're about to do calculations with it immediately. If you're gonna assign a value to it later, (e.g. via keyboard input) you can just declare it -> allocate a space in the memory for that variable but it won't have any specific value. (if you try to call it, bad things can happen)

  • @rohithaider
    @rohithaider 6 лет назад

    Best tutorials ever! I love the way you Mr. BUCKY!

  • @v1e2ridisQ3u4o
    @v1e2ridisQ3u4o 12 лет назад

    Yes, you can do it that way too.
    Though, as Bucky mentioned in an earlier tutorial, doubles take up more bytes than an integer, because it's more precise. So in a more complex program where you mainly work with integers but have one or two print-outs or returns which requires decimal precision, a typecast could be a good solution.

  • @Skorbeen
    @Skorbeen 8 лет назад +1

    Bucky, you promised at least 1 bad joke per video. You did this many videos back. I think you are russian your videos.
    On a more serious note, thank you so much man. I've been trying to find a good source to get into programming, you explain things very clear and I'm amazed with what I've built in just a couple of days with your help.
    Looking forward to watching the rest of your videos:)
    Cheers!

  • @NALDstudio
    @NALDstudio 11 лет назад

    Somewhere in the code, (line 22), we can notice that we divide the variable ageTotal by numberOfPeopleEntered. This means that if you type -1 immediately when the program launches, the numberOfPeopleEntered still contains the value of 0 as it is the default value.
    By realising that the fact dividing any number by 0 causes an equation that doesn't exist, it's simple to understand why the program crashes.
    By putting a condition that numberOfPeopleEntered must be different from 0, we're okay. :)

  • @dibbiepk
    @dibbiepk 12 лет назад

    After watching this video, I made some common mistakes when I tried it, heres my 2 mistakes I made:
    int number; - I didnt add = 0;
    cout >> "Enter first persons age or -1 to quit"

  • @constantinmanea5481
    @constantinmanea5481 3 года назад

    I really like this guy!! He convinced me to start learning C++
    The first video in the list when he say`s Hello "C-nts" killed me I was like , yeah this is where i need to start :))
    very well explained, good examples and straightforward!

  • @vulpine678
    @vulpine678 5 лет назад

    thank u so much... the explanation is clear and straightforward...

  • @xTxNarutoxTx
    @xTxNarutoxTx 12 лет назад

    I've rarely seen ads, if any at all on his videos o.o. I hope he does make money from these, he definitely deserves a lot. I bet people are passing computer science like nothing because of Bucky. If he is a millionaire he deserves it :D.

  • @d3lt4X
    @d3lt4X 5 лет назад +6

    Using your code, if you type -1 to quit when it asks you to set the first age, it's not going to work as expected.
    ageTotal and numberOfPersonEntered will be 0 because we've never entered the loop
    0 divided by 0 = crash

    • @diedie111590
      @diedie111590 5 лет назад

      who cares? you're quitting the program...

  • @LuharVasGamingOz
    @LuharVasGamingOz 11 лет назад

    Yeah it can be a bit confusing, i suggest getting a book about the basics of C++, before i started watching bucky's videos i read a book about C++ and it's history and it was all so clear to me :)

  • @nomevic
    @nomevic 9 лет назад +6

    to make sure that the program don't goes crazy if the first number you enter is -1, throw there an If statement too:
    int main()
    {
    int age;
    int ageTotal = 0;
    int nrOfPpl = 0;
    cout age;
    while(age != -1){ //this make the program stop when -1 is entered
    ageTotal += age;
    nrOfPpl++;
    cout age;
    }
    cout

    • @MoNeyAssasin
      @MoNeyAssasin 8 лет назад

      why ageTotal += age instead of ageTotal + age?

    • @matthewnaylor5894
      @matthewnaylor5894 8 лет назад +2

      ageTotal = ageTotal + age;
      is the same as:
      ageTotal += age;

    • @saurabhs4743
      @saurabhs4743 7 лет назад

      Victor Popescu if is by default check Ed in while loop. it's a while loop not do while :)

  • @TheCosmicChicken
    @TheCosmicChicken 12 лет назад +3

    "And you need to...watch more'v of my videos or something, I dunno'."
    Quite the sales pitch there, Bucky!

  • @v1e2ridisQ3u4o
    @v1e2ridisQ3u4o 12 лет назад

    Yes, you can do it the other way around too to round decimal point types like floats and doubles to integers by putting (int) before the variable.

  • @JackMcCrackenOtt
    @JackMcCrackenOtt 13 лет назад

    Bug: entering negative 1 for the first value causes division by zero (0/0) because both ageTotal and numberOfPeopleEntered are initialized to zero. You could fix it by making a if statement after the first cin read testing if the age variable is equal to -1 and simply returning zero if so.

  • @NALDstudio
    @NALDstudio 11 лет назад

    To solve the -1 problem, you need to add a if condition before dividing by the number of people. As numberOfPeopleEntered = 0 when you type -1 at the begenning, it causes a division by 0, which is impossible.
    if(numberOfPeopleEntered != 0){
    cout

  • @williamgrove9617
    @williamgrove9617 7 лет назад +4

    I think at this point it would be good to cover error handling! Especially when working with inputs!

  • @dibbiepk
    @dibbiepk 11 лет назад

    Holy crap this is gon be a big bonus for me next week... Thanks Bucky

  • @sriramiyer7504
    @sriramiyer7504 11 лет назад

    the program will never end

  • @muhammadhadad8185
    @muhammadhadad8185 7 лет назад

    Amazing!
    Love your lecture sir!

  • @AdpoGamer
    @AdpoGamer 11 лет назад

    Thank you so much for this tutorial!
    It has helped me a lot :D

  • @jigarlush6429
    @jigarlush6429 9 лет назад

    bucky so great bro you are tutorial it's make me fun i mean i got you more than my lecture

  • @mockingbird3809
    @mockingbird3809 7 лет назад

    In this program first itself is we entered -1 means the code blocks will hang, cheak it out with same command that Bucky shown

  • @TheProjekton
    @TheProjekton 10 лет назад +1

    nPeople
    It's known throughout programming that using "n" means "number of"..
    nPeople = numberOfPeople
    nRedApples = numberOfRedApples
    etc etc

  • @metznimbo29
    @metznimbo29 13 лет назад

    @Starcraft2Rogue he will be doing that, he said in the description of his last "Buckys C++ Tutorials" series(#73)

  • @george18almonte
    @george18almonte 6 лет назад

    I literally love you dude

  • @leo-rq2ei
    @leo-rq2ei 8 лет назад +13

    while(theNewBoston == good tutorials){
    cout

    • @1kalekip1
      @1kalekip1 8 лет назад

      Leandro Im gettng a parse error. Pls help!

    • @leo-rq2ei
      @leo-rq2ei 8 лет назад +1

      +Kale Kip you have to create 2 variables:
      int theNewBoston =100;
      int goodTutorials =100;
      while(theNewBoston == goodTutorials){
      cout

    • @1kalekip1
      @1kalekip1 8 лет назад

      Leandro :)

    • @sophieeeee3
      @sophieeeee3 8 лет назад +1

      You crashed my command prompt goddammit.

    • @coows
      @coows 6 лет назад

      Upgrade your computer to a dual core

  • @ThePhil652
    @ThePhil652 12 лет назад

    at the beginning ageTotal shout be = to 1
    because when you want to quit you enter -1
    if you ad cout

  • @markandrewmoran4398
    @markandrewmoran4398 3 года назад +1

    Sir i can't thank you enough fir making C++ learning easy, and I hope you continue to help people who wants to become a good programmer like you.
    Btw
    What App do you use for programming,

  • @commentor5624
    @commentor5624 8 лет назад

    Instead of using ageTotal=ageTotal+age, you can use the compound operator ageTotal+=age.

  • @chrismavian6194
    @chrismavian6194 11 лет назад

    No. The number of people entered is how many people you are including in your loop. The age total++ is adding the actual age each time a new person is introduced to your loop. Hope that helps.

  • @NoName-oq8ok
    @NoName-oq8ok 8 лет назад +3

    thaaaaaaaaaaaaaaaaaaaaaaaanks finally i got it

  • @MarijnKonings
    @MarijnKonings 11 лет назад

    No idea, a double or a float would indeed be better in this case for the result. The amount of people entered wouldn't really need a decimal number since it will always increment by 1.

  • @v1e2ridisQ3u4o
    @v1e2ridisQ3u4o 12 лет назад

    You do get a rounding error with this, for example putting 10 and 11 you should get the average 10.5, however it outputs 10. Putting a (float) before ageTotal/numberOfPeopleEntered; you get a few decimals

  • @xetrius3671
    @xetrius3671 9 лет назад

    You didn't account for the user wanting to quit before entering an age.
    For those who got an error because they entered -1 before entering an age, you can solve this with a simple test to check if the amount of ages entered is bigger then 0.
    For example:
    #include
    using namespace std;
    int main()
    {
    int age;
    int ageTotal = 0;
    int people = 0;
    cout age;
    while(age!=-1){
    ageTotal += age;
    people++;
    cout age;
    }
    if(people != 0){
    cout

  • @dibbiepk
    @dibbiepk 11 лет назад

    Thats because when the program first starts, the user hasnt entered anyone yet, so after they enter someone that value will be 1, and when they enter the next person it will be 2, and so on and so on, but it starts at 0, because they didnt enter any one yet, so its value is 0

  • @pragatiranjan9418
    @pragatiranjan9418 3 года назад +1

    in my program no.of pepole entered is always showing the actual value increased by one

  • @dkblade27
    @dkblade27 11 лет назад

    Bucky forgot to type cast the average part. Int divided by int only gives int but the average can be a decimal value. So remember to type cast.

  • @dhruvkhetrapal4279
    @dhruvkhetrapal4279 9 лет назад +1

    We could just take input from user for the no of persons.Then accordingly run the loop.

  • @Qazqi
    @Qazqi 11 лет назад

    Dividing by 0 is undefined behaviour; it doesn't have to crash.

  • @LuharVasGamingOz
    @LuharVasGamingOz 11 лет назад

    They are integer values so no they don't have to be positive. As long as they are whole numbers (meaning that they do not contain decimals) it should be fine :)

  • @Impulse_Photography
    @Impulse_Photography 6 месяцев назад

    I think, you should have use zero instead of (-1) to cause the loop to quit. Otherwise, if someone entered zero then it will do the division by zero, which could cause program to crash.

  • @Qazqi
    @Qazqi 11 лет назад

    0/0 is indeterminate. Positive or negative numbers divided by 0 are undefined.

  • @bbszn
    @bbszn 11 лет назад

    To get exact average, he would need to do ageTotal from "int" to double or float. And, I think, he would need to do "Average age"(line 22) an variable, which type would be double or float. Then he would get an exact average.

  • @NikorasuChan
    @NikorasuChan 12 лет назад

    I learnt few programming languages beforehand ;) && is means 'and', for example if there two variable, and you want to check whether both variables is equal to the value you want, and if both returns the value that you want, for example, you wanted variable a to return 1 and b to return 0, by using if (a==1 && b==0), you can then put in the code in the { } and blah blah blah... eventhough I dont know if I'm answering you XD

  • @niceheadcrab34225
    @niceheadcrab34225 11 лет назад

    You can divide by zero. A positive number divided by zero is infinity; a negative is negative infinity. I forgot what zero divided by zero was.

  • @yagamilul4479
    @yagamilul4479 4 года назад

    i just love the number 5

  • @joelsanchez3250
    @joelsanchez3250 6 лет назад

    Bucky is a great speller !!!!
    "Number of peoople eneted !!!! "

  • @BiscuitTech
    @BiscuitTech 12 лет назад

    @kojax98 That's because one of "Age" has a capital letter and the other hasn't. Make them both identical and it's gonna work.

  • @baqerghezi1342
    @baqerghezi1342 4 года назад

    you don't need to initialize the variables if you use (do - while) loop

  • @RedsBoneStuff
    @RedsBoneStuff 9 лет назад +6

    2:34 Or "nope" in short :3

  • @NALDstudio
    @NALDstudio 11 лет назад

    Also, I was trying to show the source of the problem inside the code, which was caused by the division by zero so my example was better to explain the solution to that problem.

  • @PipleKlo
    @PipleKlo 6 лет назад

    Can't you add
    cout

  • @RobertHovakimyan55
    @RobertHovakimyan55 10 лет назад +3

    My families average age is 28! Thank You, I always was curious...

  • @NeilRoy
    @NeilRoy 10 лет назад

    So if I enter -1 right away without entering any ages at all, what happens? You should always check for errors, test everything, make certain number of people entered and the total ages are both positive values. You should also check for proper values when they are input, perhaps in a range from 1 - 120. Get in the habit of checking all return values and testing everything.

  • @imamuddin8042
    @imamuddin8042 4 года назад

    You could start with age = 0 and take your first cout and cin inside the loop. And with that, you dont need to put again cin >> age at the end of loop.

    • @imamuddin8042
      @imamuddin8042 4 года назад

      Sorry my bad, in that case, first iteration of loop would always happen and it might take invalid -1 as input and will return invalid average -1

  • @intensity67
    @intensity67 13 лет назад

    Hey Bucky, sorry for this annoying interruption for a little bug but you forgot that if the user puts only 1 age in this program it'll cause wrong output i in the computation of age and number of people...
    the onlyway to fix this is to put the numberofPeopleEntered++ above the loop also...

  • @MrEpicSpace
    @MrEpicSpace 10 лет назад +12

    type -1 on first input and it should crash.

    • @AntiAnathema
      @AntiAnathema 10 лет назад +7

      Because at the end of the programme it is still trying to divide by 0.

    • @berrymckokinger9317
      @berrymckokinger9317 7 лет назад

      If you entered -1 on first input,the output would be the two cout statements......smh

    • @poinpchu
      @poinpchu 6 лет назад

      Patch fix 1.1
      if(numberOfPeopleEntered == 0)
      {
      cout

    • @mitigamespro8757
      @mitigamespro8757 6 лет назад

      What about this one: (I know it's a different subject.)
      #include
      using namespace std;
      int main()
      {
      int classnumber;
      int x=1;
      int number;
      int total=0;
      cout > classnumber;
      cout

    • @leaper7808
      @leaper7808 5 лет назад

      You can fix that by doing a pre-check.
      if (numPeople == 0 && age == -1) {
      return 0;
      }
      This way the program will exit safely without a crash.

  • @dre38w
    @dre38w 13 лет назад

    @Rigardoful haha That works too. Making the numOfPeeps an unsigned int works a LOT better than my order of operations take on it.

  • @TheWeirdTechGuy
    @TheWeirdTechGuy 13 лет назад

    @colouredmirrorball That's quite difficult because the user's input could be either a number or a letter, so it would need 2 different types of variable. Read about data validation.

  • @P4INKiller
    @P4INKiller 12 лет назад

    Yup, anytime you specify one type of data as another datatype.

  • @breenud39tv
    @breenud39tv 4 года назад +1

    I have a question, I tried entering 10000000000 just as a joke to see what would happen then it infinitely loops what I had in cout. How do I prevent that? Like how would I add a limit for age lets say so no one is allowed to enter such high numbers?

  • @Binary10100
    @Binary10100 11 лет назад

    That's because they're ints. If you wanter higher numbers, use longs.

  • @odo432
    @odo432 11 лет назад

    Modified this program using only what we have learned to get number of people, total age of people, oldest person, youngest person, and average age of people entered.

  • @luisaverhoff4884
    @luisaverhoff4884 10 лет назад +2

    Here is my own little example of this.
    #include
    using namespace std;
    int main()
    {
    int x;
    int y = 0;
    double average = 0;
    double total = 0;
    int sentinel;
    cout

  • @Kats072307
    @Kats072307 8 лет назад

    4:07 How can I type just the first few letters and make the POSSIBLE variables be displayed ? In this case it was the huge variable numberOfPeopleEntered :-)
    I'm also using CodeBlocks on a Macbook

  • @gagemachado2597
    @gagemachado2597 4 года назад

    You are a legend

  • @NikorasuChan
    @NikorasuChan 12 лет назад

    I fixed it by checking the last two code using if(ageTotal>-1 && numberPpl > 0){//the last two codes before return 0;} I fixed the problem, but there may be other way to fix it... but I'm pretty sure this works XD

  • @RudeProdigy
    @RudeProdigy 10 лет назад

    Thank you!!!!!
    Really helpful!!!

  • @user23724
    @user23724 7 лет назад

    A more efficient way of doing it:
    #include
    using namespace std;
    int main()
    {
    int age = 0;
    int pCount = 0;
    int totAge = 0;
    int avAge = 0;
    while (age != -1)
    {
    cout > age;
    totAge = totAge + age;
    pCount++;
    }
    avAge = totAge / pCount;
    cout

  • @dibbiepk
    @dibbiepk 11 лет назад

    If I am understanding right ur problem is: It adds ur 5 numbers u enter, and thats it, doesnt display anything?
    If thats true, ur solution is:
    First, check ur code for typos, if none:
    Have it add the numbers, then store those numbers in ageTotal, then display to the user, like this:
    cout

  • @cmvisuals9182
    @cmvisuals9182 6 лет назад

    Thank you. 👏👏 October 2018

  • @JoshRenton91
    @JoshRenton91 11 лет назад

    If you use numbers that don't average to integers it doesn't give you the decimal. When do we learn about floating points? Cheers, your videos are awesome

  • @Hellgo210
    @Hellgo210 12 лет назад

    integers max value is 2^15 - 1 ( i think its 32674 but i might be wrong)

  • @edwarlkd814
    @edwarlkd814 12 лет назад

    If we want to make the function the other way, would it better to use Void function or Value returning funcition? Value returning funciton as in like make it as separate function outside the main?

  • @Bartono0128
    @Bartono0128 11 лет назад

    great tutorial, thanks :)

  • @fablanta
    @fablanta 7 лет назад

    Missed a chance to use a function to input the ages

  • @dibbiepk
    @dibbiepk 12 лет назад

    @ecence123, and @wtfgigglemonkey
    Because the program isnt fullproof, you would probaly have to have a if statement that deals with the "-" stuff, like "-2" "-1" ect, so drop a else statement in there like else() {whatever he did, cause i didint watch the video yet} Hope that helped a bit, if you need
    more help, just PM me, and ill try my best, good luck with your program

  • @NikorasuChan
    @NikorasuChan 12 лет назад

    ',' isn't going to work, its as though as you're giving two seperate parameter in a function... while && works fine to calculate if both values are what you want for 'if statement'

  • @chrismavian6194
    @chrismavian6194 11 лет назад

    Because the amount of people that you start off with is zero. The idea of the loop is to average EACH person's age. If you start at 1 then the first person's average age will not be taken into account.