A Member greeting prgram

Hi guys. I am having a hard time figuring out how to code the following;
It is for my assignment that is due tonight;

Write a program to print a particular greeting to members of a forum. The program should ask users to indicate if he/she is a new member or not. A new member will be asked to enter his/her first name and surname. Then a welcome message with the user’s name and the information on how to use the forum are displayed. An existing member will be asked to enter the date of the last visit, and a welcome message with this date will be displayed. This program should include two functions welcomeNewMemeber and welcomeExistingMemeber. Also, this program should i) allow an indefinite number (<= 20) of users to enter the above information and get the corresponding greeting, until the key ‘q’ is entered to stop this program; ii) display greetings with the following information: You are the xth new member so far or You are the xth existing member so far. The “xth” shall increase appropriately with the number of new or existing members that have been entered into this program. Note that you need to use “1st”, “2nd” and “3rd” for the first three new or existing members instead of “xth”.

and this is what I have done so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  #include <iostream>
using namespace std;

void welcomeNewMember ();
void welcomeExistingMember ();

int main ()
{
    char q;
    int member;
    int numOfMembers=0;
    while (member !=q)
    {
    cout<<"Please press 1 if you are a member or press 0 if you want to become a member: "<<endl;
    cin>>member;
    numOfMembers+=member;
    numOfMembers++;

    if (member == 1)
    {
        welcomeExistingMember();
    }
    else if (member == 0)
    {
        welcomeNewMember();
    }
    else
    {
        cout<<"You have entered an invalid number"<<endl;
    }
    }
    return 0;
}
    void welcomeExistingMember()
{
    int last_visit;
    cout<<"Please enter your last visit: "<<endl;
    cin>>last_visit;
    cout<<"Welcome, your last visit is "<<last_visit;

}

    void welcomeNewMember()
{
    char name[20];
    char surname[20];
    cout<<"Please enter your first and last name: "<<endl;
    cin>>name>>surname;
    cout<<"Welcome "<<name<<" "<<surname;
}



Any help will be appreciated :}
closed account (48T7M4Gy)
Any help will be appreciated


What particular problems are you having? I noticed it runs using the shell. No errors, just a small warning about q not being initialized and no output.
Last edited on
thank you for your reply.

As seen in the description; "You are the xth existing member so far. The “xth” shall increase appropriately with the number of new or existing members that have been entered into this program. Note that you need to use “1st”, “2nd” and “3rd” for the first three new or existing members instead of “xth”."

This is the part that I am trying to figure out. I know I need to somehow put a for loop inside functions.

Thanks
closed account (48T7M4Gy)
Setup variables and update as required:
int countOfNewMembers = ...
int countOfOLdMembers = ...

The index i of name[i] tells you what the member number is.

Set up an array of strings suffix[5]
So,
if i ==1, then suffix[1] = "st", [i] == 2, then suffix[2] = "nd"... >3 ... "th"
Last edited on
Where exactly should I put these into my source code ?

Thanks?
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <string>

using namespace std;

int main ()
{
    string name[20], surname[20];
    string suffix[4] = {" ", "st", "nd", "rd", "th" };
    
    char Quit;
    int memberType;
    int numOfMembers = 0;
    
    while ( Quit != 'q' )
    {
        cout << "Please press 1 if you are a member or press 0 if you want to become a member: "<<endl;
        cin>>memberType;
        
        if ( memberType == 0 )\
        {
            numOfMembers++;
            cout<<"Please enter your first and last name: "<<endl;
            cin >> name[numOfMembers] >> surname[numOfMembers];
            cout<<"Welcome " << name[numOfMembers] << " " << surname[numOfMembers];
            
            switch (numOfMembers) {
                case 1:
                    cout << suffix[1];
                break;
                case 2:
                    cout << suffix[2];
                break;
                // bla blah blah
                default:
                cout << suffix[4];
            }
        }
        else if ( memberType == 1 )
        {
            //blah blah blah
            // ... last_visit;
            cout<<"Welcome, your last visit is "<<last_visit;
        }
        else
            cout<<"You have entered an invalid number"<<endl;
            
        cout << "Please press q if you weant to quit, anything else to continue "<<endl;
        cin >> Quit;
    }
    return 0;
}
Last edited on
Topic archived. No new replies allowed.