My application must let a nurse enter information for a number of patients about the patients' number
of repetitions for various otherwise ordinary activities.

The nurse gets a book in the format to enter the information.

Month Date Day Activity Repetitions
January 1 Monday brushed_teeth 9
January 1 Monday combed_hair 5
January 1 Monday stepped_up_bottom_step 20
January 1 Monday cleaned_basin 40
January 2 Tuesday brushed_teeth 10

I have no luck getting information stored and looped correctly.

#include <iostream>
#include <string>

using namespace std;

struct Patient
{
    char f_name[20];
    char l_name[20];
    int pat_id;
    char month[12];
    int date;
    char Day[15];
    char activity[50];
    int activ_count = 0;
    int repetitions;
    int roll;

}
patients[4];

int main()
{
    string month = "" ;
    string months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};   
    int day_count = 0;
    int day = 0;

    // storing information
    for (int i = 0; i <= 4; ++i) //starting at patient 1
    {
        patients[i].roll = i + 1;
        cout << "Enter the patient information" << patients[i].roll << "," << endl;

        cout << "Enter first name: ";
        cin >> patients[i].f_name;

        cout << "Enter last name: ";
        cin >> patients[i].f_name;

        cout << "Enter Patient ID: ";
        cin >> patients[i].pat_id;

        cout << "Enter the month for these entries: " << endl;
        cin >> month;

        if (months[0,2,4,6,7,9,11] == month) //for months with 31 days
        {
             while (day = 1 && day <= 31)
            {
            cout << "How much activities did they do today? ";
                cin >> patients[i].activ_count;

                    if (day_count <= patients[i].activ_count )
                {
                    cout << "Enter date: ";
                    cin >> patients[i].date;

                    cout << "Enter day : ";
                    cin >> patients[i].Day;

                    cout << "Enter activity: ";
                    cin >> patients[i].activity;

                    cout << "Enter repetitions: ";
                    cin >> patients[i].repetitions;
                }
                day_count++;
                cout << "Enter date: ";
                cin >> patients[i].date;

                cout << "Enter day : ";
                cin >> patients[i].Day;

                cout << "Enter activity: ";
                cin >> patients[i].activity;

                cout << "Enter repetitions: ";
                cin >> patients[i].repetitions;

        }
            day++;
            cout << "Enter date: ";
            cin >> patients[i].date;

            cout << "Enter day : ";
            cin >> patients[i].Day;

            cout << "Enter activity: ";
            cin >> patients[i].activity;

            cout << "Enter repetitions: ";
            cin >> patients[i].repetitions;

        }

    cout << endl;

        if (months[3, 5, 8, 10] == month) //months with 30 days
        {
            while (day = 1 && day <= 31)
            {
                cout << "How much activities did they do today? ";
                cin >> patients[i].activ_count;

                if (day_count <= patients[i].activ_count)
                {
                    cout << "Enter date: ";
                    cin >> patients[i].date;

                    cout << "Enter day : ";
                    cin >> patients[i].Day;

                    cout << "Enter activity: ";
                    cin >> patients[i].activity;

                    cout << "Enter repetitions: ";
                    cin >> patients[i].repetitions;
                }
                day_count++;
                cout << "Enter date: ";
                cin >> patients[i].date;

                cout << "Enter day : ";
                cin >> patients[i].Day;

                cout << "Enter activity: ";
                cin >> patients[i].activity;

                cout << "Enter repetitions: ";
                cin >> patients[i].repetitions;

            }
            day++;
            cout << "Enter date: ";
            cin >> patients[i].date;

            cout << "Enter day : ";
            cin >> patients[i].Day;

            cout << "Enter activity: ";
            cin >> patients[i].activity;

            cout << "Enter repetitions: ";
            cin >> patients[i].repetitions;

        }

    cout << endl;

        if (months[1] == month)
        {
            while (day = 1 && day <= 31)
            {
                cout << "How much activities did they do today? ";
                cin >> patients[i].activ_count;

                if (day_count <= patients[i].activ_count)
                {
                    cout << "Enter date: ";
                    cin >> patients[i].date;

                    cout << "Enter day : ";
                    cin >> patients[i].Day;

                    cout << "Enter activity: ";
                    cin >> patients[i].activity;

                    cout << "Enter repetitions: ";
                    cin >> patients[i].repetitions;
                }
                day_count++;
                cout << "Enter date: ";
                cin >> patients[i].date;

                cout << "Enter day : ";
                cin >> patients[i].Day;

                cout << "Enter activity: ";
                cin >> patients[i].activity;

                cout << "Enter repetitions: ";
                cin >> patients[i].repetitions;

            }
            day++;
            cout << "Enter date: ";
            cin >> patients[i].date;

            cout << "Enter day : ";
            cin >> patients[i].Day;

            cout << "Enter activity: ";
            cin >> patients[i].activity;

            cout << "Enter repetitions: ";
            cin >> patients[i].repetitions;

        }

    cout << endl;

    }

cout << "Displaying Information: " << endl;

    // Displaying information
    for (int i = 0; i < 1; ++i)
    {
        cout << "\nPatient Name: " << i + 1 << endl;
        cout << "Name: " << patients[i].f_name << endl;
        cout << "ID: " << patients[i].pat_id << endl;

        cout << "month: " << endl;
        cout << "Activity: " << patients[i].activity << endl;
        cout << "rep: " << patients[i].repetitions << endl;
        cout << "date: " << patients[i].date << endl;
    }

    system("pause");
}

Recommended Answers

All 5 Replies

You posted your code instead of just posting the homework assignment. Hat's off to you.

OK, first things first. Lines 47, 99, and 151 can't be done like that. C++ doesn't allow string comparison via "==". String::compare is your friend.
http://www.cplusplus.com/reference/string/string/compare/

Second: You'll need to compare against each month instead of months[0,2,4,6,7,9,11] == month.

Third: Are you allowed to use functions? Because you have 3 identical blocks of code and they need to be squished down into a function that's called in 3 different ways.

Fourth: while (day = 1 && day <= 31) needs to be while (day >= 1 && day <= 31) and 30 and 28.

Fifth: You start the day variable at 0 so the while block is going to fail anyway.

EDIT:
Sixth: system("pause"); is a bad practice and old-timers get their knickers in a twist about it. Learn to use your IDE's debug feature.

Seventh: Totally missed this. int main should end with a return 0; right before the last bracket. And put a break point (using the IDE) on that line so you can get rid of the system("pause");.

Good luck.

Hey, thanks for the reply! Yes I can use functions but I chose to have it working fully before I implement them. Can you start me off on the compare because I'm not quite getting it.

My try was : !months[0].compare(month), !months[1].compare(month)

Is that correct?

For comparing the month entered to get number of days, I would suggest a struct with the name of the month and the number of days. A map<string,month> with the name of the month as the key and the corresponding month instance as the value. Now you can get the num of days for a particular month with a simple call to the map:

struct Month
{
    string name;
    int numDays;
};
map<string , Month> months
{
    { "January",Month{ "January",31 } },
    { "February",Month{ "February",28 } },
    { "March",Month{ "March",31 } },
    { "April",Month{ "April",30 } },
    { "May",Month{ "May",31 } },
    { "June",Month{ "June",30 } },
    { "July",Month{ "July",31 } },
    { "August",Month{ "August",31 } },
    { "September",Month{ "September",30 } },
    { "October",Month{ "October",31 } },
    { "November",Month{ "November",30 } },
    { "December",Month{ "December",31 } }
};

for(day = 1; day <= months[month].numDays; day++)

Notice how this will also eliminate alot of the repetitive code you've got

@ Jemone_1
You said:

Yes I can use functions but I choose to have it working fully before I implement them

You have it backwards ...
well named functions (procedures) are your friend to expedite logic flow ...

and to break up your project into discrete logical tasks.

And re.
@tinstaafl's map pf struct idea ...
an excellent idea ...
but it may be a little advanced for you at this stage.

You may like to just use an array of 12 struct's instead?

You will also need a functon to tell if it is a leap year
and to then add 1 to the days
if the year is a leap year and the month is the 2nd month.
(If you need help, there are many ways to code for this, and someone here will be glad to help you if you can't find a good working example to help you get started with the logic.)

If you use an array of 12 struct elements ...
a fuction to do a simple liner search for the matching month,
could suffice here.

A nice looking project ... when is it due?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.