Thread: Need some Pointers (really new to C++)

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    5

    Need some Pointers (really new to C++)

    Hey guys im new to C++ and i already have a project for my class i need some tips and help pls

    My Prof asked us to make a program that will ask this question:

    If Applicant is Male:
    if status is Single:
    Enter College Level (if on College) : (requirement 2 yrs)
    Enter Highschool level (if on highschool): (requirement 3yrs
    if status is Married:
    " " " " " " " " requirements 3 yrs)
    " " " " " " " " requirement 4 yrs)
    If Applicant is Female:
    (same as Above)


    This program should tell if the person should get accepted or not.

    and i started with a switch program but im stuck and i dont know what to do would really appreciate some pointers... im really new to this C++ THANX IN ADVANCE!

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    5
    Please guys and pointers will greatly help me

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    The switch-construction could look like something like this:

    Code:
    switch (applicant)
    {
        case male:
            switch (status)
            {
                case single:
                    /* .. */
                    break;
                case married:
                    /* .. */
                    break;
                default:
                    print_error_mg (Invalid status);
                    break;
            }
            break;
        case female:
            switch (status)
            {
                case single:
                    /* .. */
                    break;
                case married:
                    /* .. */
                    break;
                default:
                    print_error_mg (Invalid status);
                    break;
            }
            break;
        default:
            print_error_mg (Invalid sex);
            break;
    }

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    5
    Hallo thanx for the reply well i tried this setup

    #include<iostream.h>
    #include<stdio.h>
    char gender;
    int status,college,hs,cl;
    main ()

    {
    cout<<" Enter your Gender : " ;
    cin>> gender;
    switch (gender)
    {
    case 'M':
    cout<<" Your a Male \n";
    cout<<" Enter ur status (press 1(single) press 2 (married):" ;
    cin>> status;
    if (status==1)

    cout<<"Enter Education Level (press 1(highschool) press 2 (college) : " ;
    cin>> college;
    if (college=1)

    cout<<"Enter Highschool level : " ;
    cin>> hs;
    if (hs<3)

    cout<<"Sorry Sir but You are not qualified";
    cout<<"Hallo Sir Pls contact me for more question";

    if (status==2)
    cout<<"Enter Education Level (press 1(highschool) press 2 (college) : " ;

    cin>> college;
    if (college=1)

    cout<<"Enter Highschool level : " ;
    cin>> hs;
    if (hs<3)

    cout<<"Sorry Sir but You are not qualified";
    cout<<"Hallo Sir Pls contact me for more question";



    break;
    case 'F':
    cout<<" Your a Female ";
    break;
    default:
    cout<<" Pls press M or F";
    }
    }

    the first part work but after that im clueless and im not even sure if its right :P

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Please use codetags.

    Use constants to make code reading easier.

    You forgot a lot of { } pairs.

    If the process for Male and Female is equal, why make a difference?

    Code:
    #include<iostream.h>
    #include<stdio.h>
    
    #define MALE    'M'
    #define FEMALE  'F'
    
    enum status
    {
        SINGLE = 1,
        MARRIED
    };
    
    enum education
    {
        HIGHSCHOOL = 1,
        COLLEGE
    };
    
    
    main ()
    {
        char gender;
        int status,college,hs,cl;
    
        cout <<" Enter your Gender : " ;
        cin >> gender;
    
        switch (gender)
        {
            case MALE:
                cout << " Your a Male \n";
                cout << " Enter ur status (press 1(single) press 2 (married): ";
                cin>> status;
    
                switch (status)
                {
                    case SINGLE:
                        cout<<"Enter Education Level (press 1(highschool) press 2 (college) : ";
                        cin>> college;
    
                        if (college = HIGHSCHOOL)
                        {
                            cout<<"Enter Highschool level : ";
                            cin>> hs;
    
                            if (hs < 3)
                            {
                                cout<<"Sorry Sir but You are not qualified";
                                cout<<"Hallo Sir Pls contact me for more question";
                            }
                        }
                        break;
                    case MARRIED:
                        cout << "Enter Education Level (press 1(highschool) press 2 (college) : ";
                        cin >> college;
    
                        if (college == HIGSCHOOL)
                        {
                            cout << "Enter Highschool level : ";
                            cin >> hs;
    
                            if (hs < 3)
                            {
                                cout << "Sorry Sir but You are not qualified";
                                cout << "Hallo Sir Pls contact me for more question";
                            }
                        }
                        break;
                    default:
                        cout << "Invalid status\n";
                        break;
                }
                break;
            case FEMALE:
                // Same as above?
            default:
                cout << "Hmmm.";
                break;
        }
    
        return 0;
    }

  6. #6
    Registered User
    Join Date
    Jun 2002
    Posts
    5
    thanx for the reply!! ok well its working now... but everytime i punch in a number for the years of College/Highschool..

    cout << "Sorry Sir but You are not qualified";
    cout << "Hallo Sir Pls contact me for more question";

    they both show on the screen... how do i fix this?

  7. #7
    Registered User
    Join Date
    Jun 2002
    Posts
    5
    #include<iostream.h>
    #include<stdio.h>

    #define MALE 'M'
    #define FEMALE 'F'

    enum status
    {
    SINGLE = 1,
    MARRIED
    };

    enum education
    {
    HIGHSCHOOL = 1,
    COLLEGE = 2,
    };


    main ()
    {
    char gender;
    int status,college,hs,cl;

    cout <<" Enter your Gender : " ;
    cin >> gender;

    switch (gender)
    {
    case MALE:
    cout << " Your a Male \n";
    cout << " Enter ur status (press 1(single) press 2 (married): ";
    cin>> status;

    switch (status)
    {
    case SINGLE:
    cout<<"Enter Education Level (press 1(highschool) press 2 (college) : ";
    cin>> college;

    if (college = HIGHSCHOOL)
    {
    cout<<"Enter Highschool level : ";
    cin>> hs;

    if (hs <= 3)
    {
    cout<<"Sorry Sir but You are not qualified";
    cout<<"Hallo Sir Pls contact me for more question";
    }

    else if(COLLEGE)
    {
    cout<<"Enter College level: ";
    cin>> cl;

    if (cl <= 3)
    {
    cout<<"sorry hehehe";
    cout<<" ok";
    }
    }



    break;
    case MARRIED:
    cout << "Enter Education Level (press 1(highschool) press 2 (college) : ";
    cin >> college;

    if (college == HIGHSCHOOL)
    {
    cout << "Enter Highschool level : ";
    cin >> hs;

    if (hs < 3)
    {
    cout << "Sorry Sir but You are not qualified";

    cout << "Hallo Sir Pls contact me for more question";
    }
    }
    break;

    cout << "Invalid status\n";
    break;
    }
    break;
    case FEMALE:
    // Same as above?
    default:
    cout << "Hmmm.";
    break;
    }

    return 0;
    }
    }

    can someone try running this? i havent finished the Famale part so just check the upper part

  8. #8
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    you missed the part on using code tags even tho i pefer the php tags. if you just copy an dpaste in thw code it is in a list, if u do something like

    <php>code here</php> but using [ and ] instead of < and > it keeps where yuo indented the code on the post. if you do not indent pointers in your code or lines to be seperarted like the guyy posted previsoulyyou will find programmign harder then it is!


    reading
    PHP Code:
    #include<iostream.h>
    #include<stdio.h>

    #define MALE    'M'
    #define FEMALE  'F'

    enum status
    {
        
    SINGLE 1,
        
    MARRIED
    };

    enum education
    {
        
    HIGHSCHOOL 1,
        
    COLLEGE
    };


    main ()
    {
        
    char gender;
        
    int status,college,hs,cl;

        
    cout <<" Enter your Gender : " ;
        
    cin >> gender;

        switch (
    gender)
        {
            case 
    MALE:
                
    cout << " Your a Male \n";
                
    cout << " Enter ur status (press 1(single) press 2 (married): ";
                
    cin>> status;

                switch (
    status)
                {
                    case 
    SINGLE:
                        
    cout<<"Enter Education Level (press 1(highschool) press 2 (college) : ";
                        
    cin>> college;

                        if (
    college HIGHSCHOOL)
                        {
                            
    cout<<"Enter Highschool level : ";
                            
    cin>> hs;

                            if (
    hs 3)
                            {
                                
    cout<<"Sorry Sir but You are not qualified";
                                
    cout<<"Hallo Sir Pls contact me for more question";
                            }
                        }
                        break;
                    case 
    MARRIED:
                        
    cout << "Enter Education Level (press 1(highschool) press 2 (college) : ";
                        
    cin >> college;

                        if (
    college == HIGSCHOOL)
                        {
                            
    cout << "Enter Highschool level : ";
                            
    cin >> hs;

                            if (
    hs 3)
                            {
                                
    cout << "Sorry Sir but You are not qualified";
                                
    cout << "Hallo Sir Pls contact me for more question";
                            }
                        }
                        break;
                    default:
                        
    cout << "Invalid status\n";
                        break;
                }
                break;
            case 
    FEMALE:
                
    // Same as above?
            
    default:
                
    cout << "Hmmm.";
                break;
        }

        return 
    0;

    is easier than reading just

    #include<iostream.h>
    #include<stdio.h>

    #define MALE 'M'
    #define FEMALE 'F'

    enum status
    {
    SINGLE = 1,
    MARRIED
    };

    enum education
    {
    HIGHSCHOOL = 1,
    COLLEGE
    };


    main ()
    {
    char gender;
    int status,college,hs,cl;

    cout <<" Enter your Gender : " ;
    cin >> gender;

    switch (gender)
    {
    case MALE:
    cout << " Your a Male \n";
    cout << " Enter ur status (press 1(single) press 2 (married): ";
    cin>> status;

    switch (status)
    {
    case SINGLE:
    cout<<"Enter Education Level (press 1(highschool) press 2 (college) : ";
    cin>> college;

    if (college = HIGHSCHOOL)
    {
    cout<<"Enter Highschool level : ";
    cin>> hs;

    if (hs < 3)
    {
    cout<<"Sorry Sir but You are not qualified";
    cout<<"Hallo Sir Pls contact me for more question";
    }
    }
    break;
    case MARRIED:
    cout << "Enter Education Level (press 1(highschool) press 2 (college) : ";
    cin >> college;

    if (college == HIGSCHOOL)
    {
    cout << "Enter Highschool level : ";
    cin >> hs;

    if (hs < 3)
    {
    cout << "Sorry Sir but You are not qualified";
    cout << "Hallo Sir Pls contact me for more question";
    }
    }
    break;
    default:
    cout << "Invalid status\n";
    break;
    }
    break;
    case FEMALE:
    // Same as above?
    default:
    cout << "Hmmm.";
    break;
    }

    return 0;
    }
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MergeSort with array of pointers
    By lionheart in forum C Programming
    Replies: 18
    Last Post: 08-01-2008, 10:23 AM
  2. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM