- 
                C++ Problemabout 10 years ago 
- 
          
          about 10 years ago After going through your code, i found that inside the "checkage()" function, you have initialized the variables "eldest" and "youngest" to "age[0]" (i.e whatever be your element at 0th index). And inside both the for loops you are checking the condition 
 if(age[i ]> eldest) and if(age[i] < youngest),
 these conditions will evaluate to false if your "youngest" or "eldest" person's age is present at 0th index(age[0]) (Because (a < a) or (a > a) is always false, i.e no integer number can be smaller or greater than itself).Thus "e_name" & "y_name" will never get initialized in such case. And u won't be able to print there values in this condition.To overcome this, either you can initialize "e_name" & "y_name" to name[0] initially. like: 
 e_name =name[0];
 y_name = name[0];Or, instead of "<" and ">" you can check for "<=" and ">=" inside the if conditions. 
- 
          
- 
          
          about 10 years ago Hello there, There was one problem in your if condition inside "checkage()" function. You assigned youngest and eldest to a[0] in this case if eldest or oldest be at index 0 then your if condition will return false ( 1 < 1 will return false ) please uncomment your program accordingly as i was testing in linux environment, so i had to comment some lines.. 
- 
          
 
                      
                      
                      
    
    
 
               
               
 
               
               

2 Answer(s)