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!
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! ;-)
" 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
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.
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.
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!
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)
@@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...
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!
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;
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
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)
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)
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.
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!
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. :)
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"
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!
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.
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
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 :)
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
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.
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
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,
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.
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.
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
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
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
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 :)
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.
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.
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
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.
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.
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.
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...
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
@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.
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?
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.
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
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
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
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
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
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
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?
@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
',' 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'
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.
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!
Just curious but does learning C++ help with CS?
@@beri4138 the idea is that if you can learn c++ the lowest level language you can learn higher level languages
@@lich.possum where do you get that idea from? And what do you mean by "lowest level language"?
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! ;-)
+Samir Gunic thx.. I was wondering just this! :)
oh cool, thanks for explaining that.
sentinel vs scourge yun pare
" 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
@@hetaeramancer no way?! You need to get a sense of humor. Relax, we are not in school here.
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.
I like how he makes everything sound so easy. Something to definitely work towards.
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.
Nice tutorial, it would have been great if you gave us exercises at the end of each video, thanks for the tutorials.
@Sourin 2 🤦♂️
Woot. Have watched 20 of your C++ tutorials in 2 days! Aiming to watch 10 a day until I have finished your series!
Really ??
Mee to @zak
@@reshavraj4090 Awesome! (yes I did finish the series)
@@RCTestKid Any suggestions..for data str and algo.!!
@@reshavraj4090 Sorry, I don't know what you're asking.
cout
#include
using namespace std:
main()
{
int myAge;
cin >> myAge;
if (myAge > 1) {
cout
its using namespace std;
and int main()
*RETURN 0;*
@@yaboi3749 yeah you are right........ YA BOI
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!
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)
WhosTheBossHD but if he didn't make total age 0 than it would've been null and u cant add to null
+KomodoPanther what he means is that he should've probably added an if (NumberOfPeopleEntered != 0) statement over cout
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.
how the hell could it be 0 though? idiot...
@@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...
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!
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.
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;
Man, what are you? You are teaching way more better than many paid tutors. You deserve more than this
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
I love all your work Bucky. Thank you for making these tutorials :).
guys keep clicking onto each concurrent video every second and you get a really cool mix of "hows it goin guys"
ads!!
adblock!!
Don't use adblock on his vids, this is his income...
This was much more entertaining than I thought it'd be
When you declare your variables, always set it to 0 because it can get random values if you don't
int numberOfPeopleEntered
can be shortened to
int nope
I put numberOPE
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)
None of our suggestions is wrong actually. Both are very simple to type and to understand.
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)
Best tutorials ever! I love the way you Mr. BUCKY!
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.
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!
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. :)
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"
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!
thank u so much... the explanation is clear and straightforward...
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.
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
who cares? you're quitting the program...
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 :)
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
why ageTotal += age instead of ageTotal + age?
ageTotal = ageTotal + age;
is the same as:
ageTotal += age;
Victor Popescu if is by default check Ed in while loop. it's a while loop not do while :)
"And you need to...watch more'v of my videos or something, I dunno'."
Quite the sales pitch there, Bucky!
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.
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.
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
I think at this point it would be good to cover error handling! Especially when working with inputs!
Holy crap this is gon be a big bonus for me next week... Thanks Bucky
the program will never end
Amazing!
Love your lecture sir!
Thank you so much for this tutorial!
It has helped me a lot :D
bucky so great bro you are tutorial it's make me fun i mean i got you more than my lecture
In this program first itself is we entered -1 means the code blocks will hang, cheak it out with same command that Bucky shown
nPeople
It's known throughout programming that using "n" means "number of"..
nPeople = numberOfPeople
nRedApples = numberOfRedApples
etc etc
@Starcraft2Rogue he will be doing that, he said in the description of his last "Buckys C++ Tutorials" series(#73)
I literally love you dude
while(theNewBoston == good tutorials){
cout
Leandro Im gettng a parse error. Pls help!
+Kale Kip you have to create 2 variables:
int theNewBoston =100;
int goodTutorials =100;
while(theNewBoston == goodTutorials){
cout
Leandro :)
You crashed my command prompt goddammit.
Upgrade your computer to a dual core
at the beginning ageTotal shout be = to 1
because when you want to quit you enter -1
if you ad cout
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,
Instead of using ageTotal=ageTotal+age, you can use the compound operator ageTotal+=age.
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.
thaaaaaaaaaaaaaaaaaaaaaaaanks finally i got it
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.
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
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
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
in my program no.of pepole entered is always showing the actual value increased by one
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.
We could just take input from user for the no of persons.Then accordingly run the loop.
Dividing by 0 is undefined behaviour; it doesn't have to crash.
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 :)
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.
0/0 is indeterminate. Positive or negative numbers divided by 0 are undefined.
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.
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
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.
i just love the number 5
Bucky is a great speller !!!!
"Number of peoople eneted !!!! "
@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.
you don't need to initialize the variables if you use (do - while) loop
2:34 Or "nope" in short :3
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.
Can't you add
cout
My families average age is 28! Thank You, I always was curious...
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.
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.
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
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...
type -1 on first input and it should crash.
Because at the end of the programme it is still trying to divide by 0.
If you entered -1 on first input,the output would be the two cout statements......smh
Patch fix 1.1
if(numberOfPeopleEntered == 0)
{
cout
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
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.
@Rigardoful haha That works too. Making the numOfPeeps an unsigned int works a LOT better than my order of operations take on it.
@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.
Yup, anytime you specify one type of data as another datatype.
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?
That's because they're ints. If you wanter higher numbers, use longs.
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.
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
this is bad programming practice use relevant variables not x and y
how?
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
You are a legend
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
Thank you!!!!!
Really helpful!!!
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
Thank you, good sir.
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
Thank you. 👏👏 October 2018
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
integers max value is 2^15 - 1 ( i think its 32674 but i might be wrong)
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?
great tutorial, thanks :)
Missed a chance to use a function to input the ages
@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
',' 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'
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.