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

Pages: 12
I would like to break off parts of the vector into three or less smaller vectors.
jasonwynn10 wrote:
I would like to break off parts of the vector into three or less smaller vectors.
Would you mind explaining in more detail what you are trying to accomplish/what you mean?
I would like to take the first three chores from the randomized list and move them to vector<string> kid1, kid2, and kid3.
Last edited on
ok, I fixed it with this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
for (gameIter = gameList.begin(); a!=3;) {
				cout <<"\t"<< *gameIter << endl;
				++gameIter;
				a++;
			}
			a=0;
			cout << "And Faith has:\n";
while (a!=3){
    cout <<"\t"<< *gameIter << endl;
    ++gameIter;
    a++;
}
    a=0;
    cout << "And Steven has:\n";
while (a!=3){
    cout <<"\t"<< *gameIter << endl;
    ++gameIter;
    a++;

}
A map would probably be better because what if there are more/less than 9 chores?
code update:
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
//A program that controls a list of chores
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <ctime>
#include <windows.h>
using namespace std;

string addGame, removeGame,addPerson;
vector<string> gameList,people;
vector<string>::iterator gameIter,personIter;
unsigned seed = time(NULL);
void reset();
int x=0, old, userSelection = 0, numberOfGames = gameList.size(), a=0, kids_number, choredivisions,kidsorg,cv=0;


void chore_assigner()
{
            printf("How many kids are here?");
            cin >> kids_number;
            kidsorg=kids_number;
            choredivisions=numberOfGames/kids_number;
while(kidsorg<6){
            shuffle (gameList.begin(), gameList.end(),default_random_engine(seed));
while(0!=kids_number){
            cout << "Who is here?\n";
            cin.get();
			getline(cin, addPerson);
			people.push_back(addPerson);
			cin.clear();
			cin.sync();
			kids_number--;
			}
			kids_number=0;
            cout << endl<<endl;
while(cv!=kidsorg){
            personIter=people.begin();
            gameIter = gameList.begin();
            cout <<"\t"<< *personIter <<" has:\n"<< endl;
while (a!=choredivisions) {
            cout <<"\t"<< *gameIter << endl;
            gameIter++;
            a++;
			}
			system("pause");
			a=0;
        cv++;
        personIter++;
        }cout << "Unassigned Chore: " << *gameIter << endl;
        Sleep(3000);
        kidsorg=0;
        }
numberOfGames=gameList.size();
reset();
}
int main()
{
	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, Counter, and Mirror");
	gameList.push_back("1st Floor Bathroom Floor");
	gameList.push_back("1st Floor Bathroom Sink and Mirror");
	gameList.push_back("1st Floor Bathroom Toilet");
	//gameList.push_back("");
	numberOfGames = gameList.size();
	cout << "Welcome to your Chore List!\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;
			x++;
			old=x;
			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
			x=old;
		    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:
			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()
{
    gameList.clear();
    Sleep(2000);
    printf("Please Press Five");
    system("cls");
    main();
}
Last edited on
Calling main() from a function is bad.
using system isn't good (http://www.cplusplus.com/articles/j3wTURfi/)

1
2
		return a;
			break;

why have a break when you are always returning on the line before?

what is 'default_random_engine'?
why use c-style output (printf), and then c++ style input (cin)?

choredivisions = numberOfGames / kids_number;

if number of games is 2 and kids_number is 3, what do you think the result will be?
Default_random_engine is from <random>, it is a type of randomiser.
Two kids would get one chore and one would be left to you to be assigned.
Last edited on
Two kids would get one chore and one would be left to you to be assigned.


Sorry, i should have explained a little bit more.

THese varaibles:
choredivisions = numberOfGames / kids_number;
are all integers. Two divided by three is equal to zero.
but the unassigned chore is still applied as unassigned.
Last edited on
problem solved! Thanks for all the help!
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
Topic archived. No new replies allowed.
Pages: 12