Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,076 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,590 people online right now. Registration is fast and FREE... Join Now!




help with this c++ homework

 
Closed TopicStart new topic

help with this c++ homework, program for ages

c++izhere
20 Apr, 2008 - 08:45 PM
Post #1

New D.I.C Head
*

Joined: 12 Mar, 2007
Posts: 41


My Contributions
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;
}
  


This post has been edited by c++izhere: 21 Apr, 2008 - 06:11 PM
User is offlineProfile CardPM
+Quote Post

bodom658
RE: Help With This C++ Homework
20 Apr, 2008 - 10:30 PM
Post #2

D.I.C Head
**

Joined: 22 Feb, 2008
Posts: 150



Thanked: 5 times
My Contributions
There are a few things you should consider. Your while loop is going to give you an error, or at least a warning, because max is undefined. Try rewriting the code so you test each entry as it is entered. Have the while loop run until the exit code is crossed. Heres an idea to work with:

cpp

int age, code = 1;
while (code != 0){
std::cin>>code>>age;
if(...)//etc, etc..
}


Also, please put your code in [code*] [/code*] brackets (without *)

Hope i've helped
User is offlineProfile CardPM
+Quote Post

c++izhere
RE: Help With This C++ Homework
21 Apr, 2008 - 10:47 AM
Post #3

New D.I.C Head
*

Joined: 12 Mar, 2007
Posts: 41


My Contributions
QUOTE(bodom658 @ 20 Apr, 2008 - 11:30 PM) *

There are a few things you should consider. Your while loop is going to give you an error, or at least a warning, because max is undefined. Try rewriting the code so you test each entry as it is entered. Have the while loop run until the exit code is crossed. Heres an idea to work with:

cpp

int age, code = 1;
while (code != 0){
std::cin>>code>>age;
if(...)//etc, etc..
}


Also, please put your code in [code*] [/code*] brackets (without *)

Hope i've helped



thanks man. how does it look now

User is offlineProfile CardPM
+Quote Post

Closed TopicStart new topic
Time is now: 12/1/08 07:26PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month