Arrays

I'm creating an array that will be used to represent the products selected by the customer (program user). Can anyone help me out with this? Not really sure how I would do this or what it would look like.

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
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <fstream>
#include <string.h>
#include <cstdlib>
#include <string>
using namespace std;

class customer_info { /* Here we define our very own special type customer_info */
private: //Contain and prevent other from accidently or purposing modifying bypassing our functions below. Usually implement variables here.

public: //Here we will have our public interface of which the user can pick and choose from. Usually implement specialized functions.
	string firstname, lastname;
	string phonenumber;
	string address; //Declare our member variables for our customers info
	string ccard;
	string expdate;
	string cid;
	void setfirstname(string newfirstname) { //Public function to set the first name.
		firstname = newfirstname; //Initialize our member function to a new name
	}
	string getfirstname() { //Public function to retrieve the first name of this particular customer.
		return firstname; //Return back to the user this customer's name.
	}
	void setlastname(string newlastname) {
		lastname = newlastname;
	}
	string getlastname() {
		return lastname;
	}
	void setphonenumber(string newphonenumber) {
		phonenumber = newphonenumber;
	}
	string getphonenumber() {
		return phonenumber;
	}
	void setaddress(string newaddress) {
		address = newaddress;
	}
	string getaddress() {
		return address;
	}
	void setccard(string newccard) {
		ccard = newccard;
	}
	string getccard() {
		return ccard;
	}
	void setexpdate(string newexpdate) {
		expdate = newexpdate;
	}
	string getexpdate() {
		return expdate;
	}
	void setcid(string newcid) {
		cid = newcid;
	}
	string getcid() {
		return cid;
	}
};

customer_info WelcomeCustomer()
{
	customer_info cust;
	cout << "Enter your first and last name:" << endl;
	cin >> cust.firstname >> cust.lastname;
	cout << "Enter your phone number with no spaces:" << endl;
	cin >> cust.phonenumber;
	cout << "Enter your full address with no punctuation:" << endl;
	cin.ignore();
	getline(cin, cust.address);
	cout << "Enter your credit card number:" << endl;
	cin >> cust.ccard;
	cout << "Enter your credit card expiration date in month/year format:" << endl;
	cin >> cust.expdate;
	cout << "Enter your CID:" << endl;
	cin >> cust.cid;
	cout << "Thank you for visiting our website today, " << cust.firstname << " " << cust.lastname << ". Below you will find a list of products available for purchase at this time.";
	cout << " Please enjoy your visit  on our website." << endl; // welcome message as required  
	return cust;
}
int main()
{

	customer_info cust = WelcomeCustomer();
	int quantityN; // creating quantity, size, input, brand, total, and final variables
	int quantityS;
	int quantityR;
	int quantityA;
	int quantityV;
	int quantityC;
	int sizeN;
	int sizeS;
	int sizeR;
	int sizeA;
	int sizeV;
	int sizeC;
	char inputN;
	char inputS;
	char inputR;
	char inputA;
	char inputV;
	char inputC;
	int reebok;
	int nike;
	int skechers;
	int adidas;
	int vans;
	int converse;
	int final;
	int totalN;
	int totalS;
	int totalR;
	int totalA;
	int totalV;
	int totalC;
	final = 0; // setting values to final and brands
	skechers = 55;
	nike = 60;
	reebok = 90;
	adidas = 80;
	vans = 100;
	converse = 100;

	cout << "Nike Running Shoes, sizes 8-13, blue/grey, $60" << endl;
	cout << "Skechers Shape ups, Women's sizes 3-10, pink/green, $55" << endl; // two different athletic shoe options
	cout << "Reebok Track shoes with .5 inch spikes, sizes 8-13, red/white/silver, $90" << endl;
	cout << "Adidas Long Distance Track shoes with .25 inch spikes, sizes 8-13, green/gold, $80" << endl; // two different track shoe options
	cout << "Vans, sizes 8-13, white, $100" << endl;
	cout << "Converse, sizes 8-13, black/white, $100" << endl; // two different casual shoe options

	cout << "Do you want Nike Running Shoes? Y/N" << endl; // asks user about each type of shoe
	cin >> inputN;
	if (inputN == 'Y') { // if the answer is yes (Y), the function asks the user how many and what size the user wants
		cout << "How many pair do you want? Enter a number:" << endl;
		cin >> quantityN;
		cout << "What size do you want? Enter a number:" << endl;
		cin >> sizeN;
	} // if the answer is no (N), the function moves on to the next type of shoe
	cout << "Do you want Skechers Shape ups? Y/N" << endl;
	cin >> inputS;
	if (inputS == 'Y') {
		cout << "How many pair do you want? Enter a number:" << endl;
		cin >> quantityS;
		cout << "What size do you want? Enter a number:" << endl;
		cin >> sizeS;
	}
	cout << "Do you want Reebok Track shoes? Y/N" << endl;
	cin >> inputR;
	if (inputR == 'Y') {
		cout << "How many pair do you want? Enter a number:" << endl;
		cin >> quantityR;
		cout << "What size do you want? Enter a number:" << endl;
		cin >> sizeR;
	}
	cout << "Do you want Adidas Long Distance Track shoes? Y/N" << endl;
	cin >> inputA;
	if (inputA == 'Y') {
		cout << "How many pair do you want? Enter a number:" << endl;
		cin >> quantityA;
		cout << "What size do you want? Enter a number:" << endl;
		cin >> sizeA;
	}
	cout << "Do you want Vans? Y/N" << endl;
	cin >> inputV;
	if (inputV == 'Y') {
		cout << "How many pair do you want? Enter a number:" << endl;
		cin >> quantityV;
		cout << "What size do you want? Enter a number:" << endl;
		cin >> sizeV;
	}
	cout << "Do you want Converse? Y/N" << endl;
	cin >> inputC;
	if (inputC == 'Y') {
		cout << "How many pair do you want? Enter a number:" << endl;
		cin >> quantityC;
		cout << "What size do you want? Enter a number:" << endl;
		cin >> sizeC;
	}
	cout << "You are ordering:" << endl; // the function is creating an order summary based on whether or not the user replied yes to wanting a type of shoe
	if (inputN == 'Y') {
		totalN = quantityN * nike;
		cout << quantityN << " Pair of Nike Running shoes, size " << sizeN << " for $" << totalN << endl;
	} // if the user did not want a type of shoe, the type is skipped and the function moves on to the next shoe
	if (inputS == 'Y') {
		totalS = quantityS * skechers;
		cout << quantityS << " Pair of Skechers Shape ups, size " << sizeS << " for $" << totalS << endl;
	}
	if (inputR == 'Y') {
		totalR = quantityR * reebok;
		cout << quantityR << " Pair of Reebok Track shoes, size " << sizeR << " for $" << totalR << endl;
	}
	if (inputA == 'Y') {
		totalA = quantityA * adidas;
		cout << quantityA << " Pair of Adidas Long Distance Track Shoes, size " << sizeA << " for $" << totalA << endl;
	}
	if (inputV == 'Y') {
		totalV = quantityV * vans;
		cout << quantityV << " Pair of Vans, size " << sizeV << " for $" << totalV << endl;
	}
	if (inputC == 'Y') {
		totalC = quantityC * converse;
		cout << quantityC << " Pair of Converse, size " << sizeC << " for $" << totalC << endl;
	}

	if (inputN == 'Y') { // the function is putting together a total, based on whether the user wanted the shoe or not
		final = final + totalN;
	} // if the user did not want the shoe it is skipped in the total, that way total(variable) does not have to be initialized if it is never used
	if (inputS == 'Y') {
		final = final + totalS;
	}
	if (inputR == 'Y') {
		final = final + totalR;
	}
	if (inputA == 'Y') {
		final = final + totalA;
	}
	if (inputV == 'Y') {
		final = final + totalV;
	}
	if (inputC == 'Y') {
		final = final + totalC;
	} // after the total is finished being calculated the program sends the final message, including the total cost of the shoes
	cout << "Your total purchase today is $" << final << ". Thank you for shopping with us, " << cust.firstname << " " << cust.lastname << ". Your shoes will be shipped in 3-5 business days." << endl;
	return 0;
}
You could create a class product_info like you did with customer_info and then declare an array.

1
2
3
4
const int MAX_PRODUCTS = 6;

product_info Products[MAX_PRODUCTS];
Topic archived. No new replies allowed.