Personally, I think it is much cleaner code in a for loop to declare the iterator inside. That way you don't have to go searching for the declaration elsewhere in the code, and so you can use the same name if you need to for a different variable outside the loop.
As to your indentation and tabbing, I'm not particularly fond of it. I personally like to do something like this in a code block:
That way its easier to read when you're scanning the code with your eyes. Its easier to pick out where the code block begins and ends. You crammed your for loop code all on the same columns, plus you put extra spaces in places where there shouldn't be any extra spaces, making it look like its a new code block or something, i.e.:Code:for (int i = 0; i < exampleNum; i++) {
//put 4 spaces starting from 'f' in 'for' before this line of code if it were code instead of a comment
//do stuff on this line...
//and do stuff on this line....
//etc..
}
You should also be aware that both the middle if statements will execute if the average is less than 20, meaning the output would be:Code:int familyfunct(int combinedages, int famtot){
cout<<"\nAbout to do the math.....\n\n\n";
int average = (combinedages/famtot);
cout<< average << endl << endl;
if(average>80){
cout<<"You're all old!" << endl;
}
if(average< 20){
cout<<"You're a young family!" << endl;
}
if(average< 30){
cout<<"You're getting older!" << endl;
}
else{
cout<<"You're pretty normal" << endl;
}
}
I don't think that was intentional.Quote:
You're a young family!
You're getting older!
You should use "else if" instead of "if" in the second middle one.