write a c++ program to read an unspecified number of input records. each input record will contain a code and a person's age. a code of 1 will indicate female; a code of 2 will indicate male; and a code of 0 will indicate end of input(exit code). Any other code is invalid and must display an appropriate error message. continue accepting and processing input records until the exit code is enter. Finally compute and display the following:
1. number of males 21 years old or older.
2. Number of females 21 years old or older.
3.Average age of all persons under 21.
4.total number of people
Code:#inlcude<iostream> int main() { int age, code, m_age1, male2, f_age1, f_age2 count=0,max; std::cout<<" Input code and Age or press 0 to exit and press <Enter>" <<std::endl while(code !=0) { std::cin>>code, age; } if(m_age>=21) { m_age1=m_age1+m_total m_total=m_total+m_age1 std::cout<< m_total<<std::endl; else if (f_age>=21) f_age1=f_age1+f_total f_total=f_total+f_age1 std::cout<< f_total/ f_age1<<std::endl; else f_age2=f_age2+f_total2 f_total2=f_total+f_age2 std::cout<<f_total2<<std::endl; } std::cout<< m_age2+f_age2 <<std::endl; std::cout<< f_total + m_total <<std::endl; } return 0; }



LinkBack URL
About LinkBacks




I used to be an adventurer like you... then I took an arrow to the knee.