Chore Assigner, please help ive been working on this program for 3 months non-stop!

Pages: 12
I am having a problem getting each of the chores put in a random order and given to three or less kids. I originally made it out of a game list creator. This is the code:
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <ctime>
#include <windows.h>
#include <random>
using namespace std;

string addGame, removeGame,person1,person2;
vector<string> gameList;
vector<string>::iterator gameIter;
unsigned seed = time(NULL);
void reset();
int kids_number, userSelection = 0;
int numberOfGames = gameList.size(), a=0, choredivisions;
bool Reset;

void pushback()
{
    gameList.push_back("Sweep LR");
	gameList.push_back("Sweep Hall");
	gameList.push_back("Chrome");
	gameList.push_back("Trash");
	gameList.push_back("Kids Bathroom Toilet");
	gameList.push_back("kids Bathroom Sink");
	gameList.push_back("First Floor Bathroom Floor");
	gameList.push_back("First Floor Bathroom Mirror");
	gameList.push_back("First Floor Bathroom Toilet");
	gameList.push_back("Kids Bathroom Counter");
	gameList.push_back("Kids Bathroom Mirror");
	gameList.push_back("First Floor Bathroom Sink");
	///gameList.push_back("");
	sort(gameList.begin(), gameList.end());
	numberOfGames = gameList.size();

	Reset=true;

	}
void chore_assigner()
{
            cout<<"How many kids are here?\n";
            cin >> kids_number;

            choredivisions=numberOfGames/kids_number;
            shuffle (gameList.begin(), gameList.end(),default_random_engine(seed));
switch(kids_number){
    case 3:
            printf("Jason Has:\n");
            gameIter = gameList.begin();
while (a!=choredivisions) {
            cout <<"\t"<< *gameIter << endl;
            gameIter++;
            a++;
			}
			system("pause");
			a=0;
			printf("Faith Has:\n");
while (a!=choredivisions) {
            cout <<"\t"<< *gameIter << endl;
            gameIter++;
            a++;
			}
			system("pause");
			a=0;
			printf("Steven Has:\n");
while (a!=choredivisions) {
            cout <<"\t"<< *gameIter << endl;
            a++;
            gameIter++;}
            a=0;
			system("pause");
			if(1==numberOfGames%kids_number){
        cout << "Unassigned Chore: " << *gameIter << endl;}
        else if(1<numberOfGames%kids_number){
while (a!=kids_number%numberOfGames) {
            cout <<"\t"<< *gameIter << endl;
            a++;
            gameIter++;}system("pause");}
        Sleep(3000);
        break;
///=======================================================================================================================================
    case 2:
        printf("Who is here?");
        cin>>person1;
        printf("Who else is here?");
        cin>>person2;
        cout<<person1<<" has:\n";
        gameIter = gameList.begin();
while (a!=choredivisions) {
            cout <<"\t"<< *gameIter << endl;
            gameIter++;
            a++;
			}
			system("pause");
			a=0;
			cout<<person2<<" has:\n";
while (a!=choredivisions) {
            cout <<"\t"<< *gameIter << endl;
            gameIter++;
            a++;
			}
			a=0;
			system("pause");
			if(1==numberOfGames%kids_number){
        cout << "Unassigned Chore: " << *gameIter << endl;}
        else if(1<numberOfGames%kids_number){
while (a!=kids_number%numberOfGames) {
            cout <<"\t"<< *gameIter << endl;
            a++;
            gameIter++;}system("pause");}
        break;
///=======================================================================================================================================
    case 1:
        printf("Who is here?");
        cin>>person1;
        cout<<person1<<" has:\n";
        gameIter = gameList.begin();
while (a!=choredivisions) {
            cout <<"\t"<< *gameIter << endl;
            gameIter++;
            a++;
			}
			a=0;
			system("pause");
			if(1==numberOfGames%kids_number){
        cout << "Unassigned Chore: " << *gameIter << endl;}
        else if(1<numberOfGames%kids_number){
while (a!=kids_number%numberOfGames) {
            cout <<"\t"<< *gameIter << endl;
            a++;
            gameIter++;}system("pause");}
            break;}
            reset();}
int main(void)
{
    if(Reset!=true){
    pushback();
    }
	cout << "Welcome to your Chore Assigner!\n" << endl;

	while (userSelection != 5) {

		cout << "Press 1 to add a Chore\n";
		cout << "Press 2 to remove a Chore\n";
		cout << "Press 3 to list all Chores\n";
		cout << "Press 4 to assign chores\n";
		cout << "Press 5 to quit\n" << endl;
		cout << "Type your option: ";
		cin >> userSelection;

		switch (userSelection) {
		case 1:   /// Add a title!
			cout << "\nType the names title to add: ";
			cin.get();
			getline(cin, addGame);
			gameList.push_back(addGame);
			cin.sync();
			numberOfGames++;
			cout << "\nChore successfully added.\n" << endl;
			system("pause");
			system("cls");
			break;
		case 2:   /// Remove a title!
            for (gameIter = gameList.begin(); gameIter != gameList.end(); ++gameIter) {
				cout <<"\t"<< *gameIter << endl;
			}
			cout << "\nType the Chores Exact title to remove.";

			cin.get();
			getline(cin, removeGame);
			gameIter = find(gameList.begin(), gameList.end(), removeGame);
			if (removeGame == *gameIter) {
				cout << "\nChore found!" << endl;
				gameList.erase(gameIter);
				numberOfGames--;
				cout << "Chore removed!\n" << endl;
			}
			else{
				cout << "Chore not found\n";

			}
			system("pause");
			system("cls");
			break;
		case 3:  ///List Chores
		    numberOfGames = gameList.size();
			cout << "\nYou currently have " << numberOfGames << " Chores in your list.\n" << endl;
			for (gameIter = gameList.begin(); gameIter != gameList.end(); ++gameIter) {
				cout <<"\t"<< *gameIter << endl;
			}
			cout << "\n";
			system("pause");
			system("cls");
			break;
        case 4:   ///Assign Chores
            chore_assigner();
            system("cls");
            break;
		case 5: ///end program
			cout << "Program shutdown.\n" << endl;
			system("cls");
			a=5;
			while (a!=0){
            cout << a;
            Sleep(1000);
            system("cls");
            a--;
			}
			return a;
			break;
		default:
			cout << "\nThat is not a valid selection.\n" << endl;
			break;}}return a;}
void reset()
{
    a=0;
    system("cls");
    main();}
Last edited on
I would consider using shuffle or random_shuffle. http://www.cplusplus.com/reference/algorithm/
Why do all your cases do the same thing in the switch statement??

All you have to do is store the names of kids in an array...


make a random function for the index in the array.

example cout << kids[randomkid];


same with the chores....create an array of strings

chores[indexofchore]

cout << kids[randomkid] << chores[randomchore];


if you want to add chores look into dynamic arrays.
Last edited on
Because they were unsure how to actually sort it and wanted that part replaced with the actual chores.

Though, the best solution IMHO would be to do a quick shuffle of the chores then select them in order. So person 0 has chore 0, person 10 has chore 10 ect...
okay so now I need to be able to divide the amount of chores between as many people as needed. Is there something I can use for that?
If there are 10 chores and 3 people then 2 people would get 3 chores and the third person would get 4. Something like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
auto it = chores.begin();
for(int i = 0; i < children; ++i)
{
    for(int j = 0; j < chores.size() / children; ++j)
    {
        child[i].push_back(*it);
        ++it;
    }
}

while(it != chores.end()) //any remaining chores
{
    child[children-1].push_back(*it);
    ++it;
}
[/code]
The code now is:
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
53
54
55
56
57
58
59
// A program that controls a list of chores
// When you get up, try splitting up the switch statement into seperate functions/methods
// Implement number of chores. == Partial

#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <cstdlib>
using namespace std;

int Rand=rand()%5+1;
string addGame, removeGame;
vector<string> gameList, choreList;
vector<string>::iterator gameIter;
vector<char> child;
int kids_number;
int children;
string person;
string person1;
string person2;

void chore_assigner()
{
            printf("How many kids are here?");
            cin >> kids_number;
            while((kids_number!=1||kids_number!=2)||kids_number!=3){
            if(kids_number==3){
            random_shuffle ( gameList.begin(), gameList.end() );
            auto it = gameList.begin();
            for(int i = 0; i < children; ++i)
            {
            for(int j = 0; j < gameList.size() / children; ++j)
            {
            child[i].push_back(*it);
            ++it;
            }
            }
            while(it != gameList.end()) //any remaining chores
            {
    child[children-1].push_back(*it);
    ++it;
            }
            }else if(kids_number==2){
            printf("Who is here?");
            cin >> person1 >> person2;
            random_shuffle ( gameList.begin(), gameList.end() );
            //distribute the chores evenly here
            }else if(kids_number==1){
            printf("Who is here?\n");
            cin >> person;
            system("cls");
            cout << person << " has to do these chores:\n";
            for (gameIter = gameList.begin(); gameIter != gameList.end(); ++gameIter) {
				cout <<"\t"<< *gameIter << endl;
			}}else
            printf("say Again?\n");
}}

and it is telling me this:
C:\Documents and Settings\Jason\Desktop\C++\personal projects\chore list selector\main.cpp|36|error: request for member 'push_back' in 'child.std::vector<_Tp, _Alloc>::operator[]<char, std::allocator<char> >(((std::vector<char>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<char> >::value_type {aka char}'|
C:\Documents and Settings\Jason\Desktop\C++\personal projects\chore list selector\main.cpp|42|error: request for member 'push_back' in 'child.std::vector<_Tp, _Alloc>::operator[]<char, std::allocator<char> >(((std::vector<char>::size_type)(children + -1)))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<char> >::value_type {aka char}'|
C:\Documents and Settings\Jason\Desktop\C++\personal projects\chore list selector\main.cpp|34|warning: comparison between signed and unsigned integer expressions [-Wsgn-compare]|

Please help me...
I inserted that in to my code with some modifications and now it is giving me some errors
Ex:
C:\Documents and Settings\Jason\Desktop\C++\personal projects\chore list selector\main.cpp|32|error: request for member 'push_back' in 'child.std::vector<_Tp, _Alloc>::operator[]<char, std::allocator<char> >(((std::vector<char>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<char> >::value_type {aka char}'|
C:\Documents and Settings\Jason\Desktop\C++\personal projects\chore list selector\main.cpp|38|error: request for member 'push_back' in 'child.std::vector<_Tp, _Alloc>::operator[]<char, std::allocator<char> >(((std::vector<char>::size_type)(children + -1)))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<char> >::value_type {aka char}'|
The thing is. Each child has a list of chores. So each child needs a vector. In other words a vector of vectors. std::vector<std::vector<string> >child(children);

Also, why do you have printf and cout? I would also suggest using proper indentation to make it more readable.
Last edited on
now its giving me an error
What code did you use? What error did you get? I can't read your mind :P
Line 38 and Line 32 are where the errors are.
Probably because children is undefined. It should be the number of children that you need chores for.
ok Thanks!
I says it has something to do with vector child.
Here's something to give you a basic idea

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
#include <iostream> //std::cout, std::endl
#include <vector> //std::vector<T>
#include <string> //std::string
#include <algorithm> //std::random_shuffle
#include <cstddef> //std::size_t
#include <cstdlib> //std::srand
#include <ctime> //std::time

int main()
{
    std::size_t const children = 3;
    std::vector<std::vector<std::string> >child(children); //you could also use a map
    //to map the child with their chores.
    //something like std::unordered_map<std::string, std::vector<std::string> > child
    
    std::vector<std::string> chores{"dishes", "laundry", "lawn", "cleaning", "cooking"};
    std::srand(static_cast<unsigned>(std::time(nullptr)));
    std::random_shuffle(chores.begin(), chores.end());
    auto it = chores.begin(); //auto = std::vector<std::string>::iterator in this case
    auto it2 = child.begin();
    while(it != chores.end())
    {
        if(it2 == child.end())
        {
            it2 = child.begin();
        }
        
        (it2++)->push_back(*(it++));
    }
    
    for(auto const &childIt : child)
    {
        for(auto const &chore : childIt)
        {
            std::cout << chore << ' ';
        }
        std::cout << std::endl;
    }
    
    return 0;
}
laundry cleaning 
cooking lawn 
dishes 
Last edited on
I would still need to be able to add or remove chores temporarily from the list and I would also need to be able to tell how many kids there are at one time.
Last edited on
I wasn't writing it for you. I was showing you an example of how to do it. I think the things you need to figure out for yourself are fairly trivial. If you need help with those specific things post questions with it with relevant information/code.
Last edited on
I want the output to be:
Jason has:
weeding
Sweeping
chrome
Faith has:
Etc...
Steven has:
Etc...

and I don't know how to do this.
std::unordered_map<std::string, std::vector<std::string> > childAndChores; http://www.cplusplus.com/reference/unordered_map/unordered_map/

I suppose if you really wanted you could do something like std::vector<std::pair<std::string, std::vector<std::string> > > childAndChores; as well if you chose to.
Pages: 12