Issues with my do while. And trouble with adding my stored array info.

I am having trouble with getting my do while loop to function correctly and I can't figure out how to get a totals for my sales price, sales tax and cash price from my Price_data array in my totals array in separate columns. I have a function set up on getting my totals for each one but i can't think of a way to get each one from the data array and add them together into my totals array. If anyone can please give me any tips on how to get them to work correctly I would greatly appreciate it. I've been trying for a while now and I just can't find a way to get my total function to work.





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
221
222
223
224
225
226
227
228
#include<iostream>
#include<iomanip>

using namespace std;
//Functions
unsigned int * Assign_Discounts();
int * find(char ** GENRES, char ** genres, int * counter);
char ** Genres_Function();
bool* question();
float Compute_Sales_Price(float ** Data, unsigned int * Sales_Discounts, int * counter, char ** GENRES, char ** genres, unsigned int * discount_percent);
float Compute_Tax_Ammount(float ** data, int * counter, float * taxrate);
float Compute_Cash_Price(float ** data, int * counter);
void Transaction_Input(char ** Artist_Names, char ** CD_Titles, char ** Genre, float ** Data, int * counter, float * taxrate);
void swap(float ** Data, int row1, int row2);
void bubble(char ** Artist_Names, char ** CD_Titles, char ** genres, unsigned int * discount_percent, float ** data, int * counter);

int main()
{
	char ** GENRES = Genres_Function();

	unsigned int * Sales_Discounts = Assign_Discounts();

	unsigned int * discount_percent = new unsigned int[30];

	int * counter = new int(0);

	float * taxrate = new float;

	bool * answer = new bool;
	
	int * data_counter = new int(0);

	char ** CD_Titles = new char * [30];
	for(int r = 0; r < 30; r++)
		CD_Titles [r] = new char [30];

	char ** Artist_Names = new char * [30];
	for(int r = 0; r < 30; r++)
		Artist_Names [r] = new char [30];

	float ** Price_Data = new float * [30];
	for(int r = 0; r < 30; r++)
		Price_Data [r] = new float [4];

	float ** totals = new float * [1]
	for(int r = 0;r < 30; r++)
		totals[r] = new float[3];

	char ** genres = new char * [30];
	for(int r = 0; r < 30; r ++)
		genres [r] = new char [30];
do
{
	Transaction_Input(Artist_Names, CD_Titles, genres, Price_Data, counter, taxrate);
	Price_Data[(*counter)][1] = Compute_Sales_Price(Price_Data, Sales_Discounts, counter, GENRES, genres, discount_percent);
	Price_Data[(*counter)][2] = Compute_Tax_Ammount(Price_Data, counter, taxrate);
	Price_Data[(*counter)][3] = Compute_Cash_Price(Price_Data, counter);
	*counter++;

	answer = question();

}while(*answer == false);
	



	return 0;
}
char ** Genres_Function()
{
	char ** genres = new char * [1];
	for(int r = 0; r < 7; r ++)
		genres[r]= new char[30];

	genres[0]="Classical";
	genres[1]="Country";
	genres[2]="International";
	genres[3]="Jazz";
	genres[4]="Pop";
	genres[5]="Rock";
	genres[6]="Show";

	return genres;
}

bool* question()
{
char* ans = new char;
bool* temp = new bool;
cout << "Are there more CD's to process?";
cin >> ans;
if (*ans = 'y')
	*temp = true;
if (*ans = 'n')
	*temp = false;
else 
	*temp = true;
return temp;
}
unsigned int * Assign_Discounts()
{
	unsigned int * dummyInteger_Array = new unsigned int [7];

	dummyInteger_Array[0] = 4;
	dummyInteger_Array[1] = 8;
	dummyInteger_Array[2] = 17;
	dummyInteger_Array[3] = 0;
	dummyInteger_Array[4] = 16;
	dummyInteger_Array[5] = 12;
	dummyInteger_Array[6] = 14;

	return dummyInteger_Array;

}


int * find(char ** GENRES, char ** genres, int * counter)
{
	int * loc = new int (0);
	bool * found = new bool(false);
	do
	{
		if(strcmp(GENRES[*loc],genres[*counter])==0)
			*found = true;
		else
			(*loc)++;
	}while((!*found)&&(*loc < 100);
	if(*found)
		return loc;
	else
		return(new int(-1));

}

float Compute_Cash_Price(float ** data, int * counter)
{
	float cash_price;

	cash_price = data[(*counter)][1] + data[(*counter)][2];

	return cash_price;
}
float Compute_Sales_Price(float ** Data, unsigned int * Sales_Discounts, int * counter, char ** GENRES, char ** genres, unsigned int * discount_percent)
{
	float sales_price;
	int * temploc = new int;

	temploc = find(GENRES, genres, counter);

	discount_percent[(*counter)] = Sales_Discounts[(*temploc)];

	sales_price = Data[(*counter)][0] - (discount_percent[(*counter)] * .10);

	return sales_price;
}

float Compute_Tax_Ammount(float ** data, int * counter, float * taxrate)
{
	float tax_ammount;
	tax_ammount = data[(*counter)][1] * (*taxrate);
	return tax_ammount;
}
void Compute_Totals(float ** totals, float ** data, int * counter)
{
	for(int r = 0, r < counter, r++)
		totals[1][0]=data[r][1]
		totals[1][1]=data[r][2]
		totals[1][2]=data[r][3]
}
void swap(float ** Data, int row1, int row2)
{
	float * temp;
	temp = Data[row1];
	Data[row1]= Data[row2];
	Data[row2] = temp;
}

void bubble(char ** Artist_Names, char ** CD_Titles, char ** genres, unsigned int * discount_percent, float ** data, int * counter)
{
	char * tempname = new char(40);
	char * tempCD = new char (40);
	char * tempgenre = new char(40);
	unsigned int * tempdiscount= new unsigned int;



	for(int iteration = 1; iteration < (*counter); iteration++)
		for(int index = 0; index < (*counter) - iteration; index++)
			if(strcmp( CD_Titles[index],CD_Titles[index + 1]) > 0)
			{
				strcpy(tempCD, CD_Titles[index]);
				strcpy(CD_Titles[index], CD_Titles[index + 1]);
				strcpy(CD_Titles[index + 1], tempCD);

				strcpy(tempname, Artist_Names[index]);
				strcpy(Artist_Names[index], Artist_Names[index + 1]);
				strcpy(Artist_Names[index + 1], tempname);

				strcpy(tempgenre, genres[index]);
				strcpy(genres[index], genres[index + 1]);
				strcpy(genres[index + 1], tempgenre);
				
				*tempdiscount = discount_percent[index];
				discount_percent[index]=discount_percent[index + 1];
				discount_percent[index+1] = *tempdiscount;

				swap(data, index, index+1);

			}
}
void Transaction_Input(char ** Artist_Names, char ** CD_Titles, char ** Genre, float ** Data, int * counter, float * taxrate)
{
	cout << "Enter the artist's name: ";
	cin.getline(Artist_Names[(*counter)],30,'\n');

	cout << "Enter the CD Title: ";
	cin.getline(CD_Titles[(*counter)],30,'\n');

	cout << "Enter the Genre: ";
	cin >> Genre[(*counter)];
//Data : list price, sales price, sales tax, cash price
	cout << "Enter the List Price: ";
	cin >> Data[(*counter)][0];

	cout << "Enter the Tax: ";
	cin >> *taxrate;
}
Last edited on
Corrected 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
221
222
223
224
225
226
227
228
229
230
#include<iostream>
#include<iomanip>

using namespace std;
//Functions
unsigned int * Assign_Discounts();
int * find(char ** GENRES, char ** genres, int * counter);
char ** Genres_Function();
bool* question();
float Compute_Sales_Price(float ** Data, unsigned int * Sales_Discounts, int * counter, char ** GENRES, char ** genres, unsigned int * discount_percent);
float Compute_Tax_Ammount(float ** data, int * counter, float * taxrate);
float Compute_Cash_Price(float ** data, int * counter);
void Transaction_Input(char ** Artist_Names, char ** CD_Titles, char ** Genre, float ** Data, int * counter, float * taxrate);
void swap(float ** Data, int row1, int row2);
void bubble(char ** Artist_Names, char ** CD_Titles, char ** genres, unsigned int * discount_percent, float ** data, int * counter);

int main()
{
        char ** GENRES = Genres_Function();

        unsigned int * Sales_Discounts = Assign_Discounts();

        unsigned int * discount_percent = new unsigned int[30];

        int * counter = new int(0);

        float * taxrate = new float;

        bool * answer = new bool;

        int * data_counter = new int(0);

        char ** CD_Titles = new char * [30];
        for(int r = 0; r < 30; r++)
                CD_Titles [r] = new char [30];

        char ** Artist_Names = new char * [30];
        for(int r = 0; r < 30; r++)
                Artist_Names [r] = new char [30];

        float ** Price_Data = new float * [30];
        for(int r = 0; r < 30; r++)
                Price_Data [r] = new float [4];

        float ** totals = new float * [1];
        for(int r = 0;r < 30; r++)
                totals[r] = new float[3];

        char ** genres = new char * [30];
        for(int r = 0; r < 30; r ++)
                genres [r] = new char [30];
do
{
        Transaction_Input(Artist_Names, CD_Titles, genres, Price_Data, counter, taxrate);
        Price_Data[(*counter)][1] = Compute_Sales_Price(Price_Data, Sales_Discounts, counter, GENRES, genres, discount_percent);
        Price_Data[(*counter)][2] = Compute_Tax_Ammount(Price_Data, counter, taxrate);
        Price_Data[(*counter)][3] = Compute_Cash_Price(Price_Data, counter);
        *counter++;

        answer = question();

}while(*answer == false);




        return 0;
}
char ** Genres_Function()
{
        char ** genres = new char * [1];
        for(int r = 0; r < 7; r ++)
                genres[r]= new char[30];

        genres[0]="Classical";
        genres[1]="Country";
        genres[2]="International";
        genres[3]="Jazz";
        genres[4]="Pop";
        genres[5]="Rock";
        genres[6]="Show";

        return genres;
}

bool* question()
{
char* ans = new char;
bool* temp = new bool;
cout << "Are there more CD's to process?";
cin >> ans;
if (*ans = 'y')
        *temp = true;
if (*ans = 'n')
        *temp = false;
else
        *temp = true;
return temp;
}
unsigned int * Assign_Discounts()
{
        unsigned int * dummyInteger_Array = new unsigned int [7];

        dummyInteger_Array[0] = 4;
        dummyInteger_Array[1] = 8;
        dummyInteger_Array[2] = 17;
        dummyInteger_Array[3] = 0;
        dummyInteger_Array[4] = 16;
        dummyInteger_Array[5] = 12;
        dummyInteger_Array[6] = 14;

        return dummyInteger_Array;

}


int * find(char ** GENRES, char ** genres, int * counter)
{
        int * loc = new int (0);
        bool * found = new bool(false);
        do
        {
                if(strcmp(GENRES[*loc],genres[*counter])==0)
                        *found = true;
                else
                        (*loc)++;
        }while((!*found)&&(*loc < 100));
        if(*found)
                return loc;
        else
                return(new int(-1));

}

float Compute_Cash_Price(float ** data, int * counter)
{
        float cash_price;

        cash_price = data[(*counter)][1] + data[(*counter)][2];

        return cash_price;
}
float Compute_Sales_Price(float ** Data, unsigned int * Sales_Discounts, int * counter, char ** GENRES, char ** genres, unsigned int * discount_percent)
{
        float sales_price;
        int * temploc = new int;

        temploc = find(GENRES, genres, counter);

        discount_percent[(*counter)] = Sales_Discounts[(*temploc)];

        sales_price = Data[(*counter)][0] - (discount_percent[(*counter)] * .10);

        return sales_price;
}

float Compute_Tax_Ammount(float ** data, int * counter, float * taxrate)
{
        float tax_ammount;
        tax_ammount = data[(*counter)][1] * (*taxrate);
        return tax_ammount;
}
void Compute_Totals(float ** totals, float ** data, int * counter)
{
        for(int r = 0; r < *counter; r++) {
                totals[1][0]=data[r][1];
                totals[1][1]=data[r][2];
                totals[1][2]=data[r][3];
        }
}
void swap(float ** Data, int row1, int row2)
{
        float * temp;
        temp = Data[row1];
        Data[row1]= Data[row2];
        Data[row2] = temp;
}

void bubble(char ** Artist_Names, char ** CD_Titles, char ** genres, unsigned int * discount_percent, float ** data, int * counter)
{
        char * tempname = new char(40);
        char * tempCD = new char (40);
        char * tempgenre = new char(40);
        unsigned int * tempdiscount= new unsigned int;



        for(int iteration = 1; iteration < (*counter); iteration++)
                for(int index = 0; index < (*counter) - iteration; index++)
                        if(strcmp( CD_Titles[index],CD_Titles[index + 1]) > 0)
                        {
                                strcpy(tempCD, CD_Titles[index]);
                                strcpy(CD_Titles[index], CD_Titles[index + 1]);
                                strcpy(CD_Titles[index + 1], tempCD);

                                strcpy(tempname, Artist_Names[index]);
                                strcpy(Artist_Names[index], Artist_Names[index + 1]);
                                strcpy(Artist_Names[index + 1], tempname);

                                strcpy(tempgenre, genres[index]);
                                strcpy(genres[index], genres[index + 1]);
                                strcpy(genres[index + 1], tempgenre);

                                *tempdiscount = discount_percent[index];
                                discount_percent[index]=discount_percent[index + 1];
                                discount_percent[index+1] = *tempdiscount;

                                swap(data, index, index+1);

                        }
}
void Transaction_Input(char ** Artist_Names, char ** CD_Titles, char ** Genre, float ** Data, int * counter, float * taxrate)
{
        cout << "Enter the artist's name: ";
        cin.getline(Artist_Names[(*counter)],30,'\n');

        cout << "Enter the CD Title: ";
        cin.getline(CD_Titles[(*counter)],30,'\n');

        cout << "Enter the Genre: ";
        cin >> Genre[(*counter)];
//Data : list price, sales price, sales tax, cash price
        cout << "Enter the List Price: ";
        cin >> Data[(*counter)][0];

        cout << "Enter the Tax: ";
        cin >> *taxrate;
}

My do whille loop still causes my program to crash. and i cant figure out how t add up my price data array.
Topic archived. No new replies allowed.