C++ Function help ASAP!!!

Please look through my code and help where it is commented I am having a great deal of trouble with this assignment and I am out of time please assist.

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
 #include <iostream>
#include <string>
#include <iomanip>
#include <sstream> // stringstream
#include <cctype> // isalph, isdigit

class Customer {
	const std::string custName, custAddress;
public:
	void custInfo(std::ostream &) const
	{
		std::cout << "Name" << custName << "\n"
			"Address" << custAddress << "\n" << std::endl;
	}
	void custWelcome(std::ostream &) const
	{
		std::cout << "\nHello " << custName << "\nAddress: " << custAddress << std::endl;
	}
	std::string custValue() const
	{
		return custName;
	}

	Customer(const std::string &inputCustName, const std::string &inputCustAddress)
		: custName(inputCustName), custAddress(inputCustAddress)
	{
	}
};

struct Beverage {
	const std::string name;
	double price;

	void bevInfo(std::ostream &) const
	{
		std::cout << "Name" << name << "\n"
			<< "Price" << "$" << price << "\n"
			<< "Total" << "$" << std::endl;
	}
	void bevSelect(std::ostream &) const
	{
		std::cout << "Selection: " << name << ", price per unit: $" << price << std::endl;
	}
	Beverage(const std::string &bevName, double bevPrice)
		: name(bevName), price(bevPrice)
	{
	}
};


const int AVAILABLE_PRODUCTS_COUNT = 3;
const Beverage AVAILABLE_PRODUCTS[AVAILABLE_PRODUCTS_COUNT] = {
	Beverage("Water", 1.45),
	Beverage("Soda", 2.98),
	Beverage("Ice Tea", 3.29)
};

typedef int Quantities[AVAILABLE_PRODUCTS_COUNT];


double totalCost(Quantities);
void orderSummary(Quantities);
std::string getStringFromUser(const std::string &prompt);
char getCharFromUser(const std::string &prompt);
Customer getCustomerFromUser();
void displayMenu(const Customer &);
void loadProductQuantity(const Beverage &, Quantities);
void doneShowOrder(const Customer &, Quantities);

double totalCost(Quantities)//NOT SURE IF IT IS CORRECT
{
	double totalCost = 0;

	for (int i = 0; i < AVAILABLE_PRODUCTS_COUNT; i++) {
		totalCost += (AVAILABLE_PRODUCTS_COUNT*AVAILABLE_PRODUCTS_COUNT);
	}
	return totalCost;

}

void loadProductQuantity(const Beverage &, Quantities)//NEED HELP FIGURING OUT WHAT DO DO
{

}

void doneShowOrder(const Customer &, Quantities)//NEED HELP FIGURING OUT WHAT DO DO
{

}

void displayMenu(const Customer &prompt)//NOT SURE IF IT IS CORRECT
{
	std::cout << std::endl << std::endl
		<< &prompt
		<< ", Please select the beverage you would like to purchase from the menu: "
		<< std::endl;

	std::cout << "Drink Menu" << std::endl;
	std::cout << "========" << std::endl;
	std::cout << "1 - Water $1.45" << std::endl;
	std::cout << "2 - Soda $2.98" << std::endl;
	std::cout << "3 - Iced Tea $3.29" << std::endl;
	std::cout << "X - Exit " << std::endl << std::endl;
}

void getStringFromUser(std::string &prompt)//NEED HELP FIGURING OUT WHAT DO DO
{
	
}

char getCharFromUser(std::string &prompt)//NEED HELP FIGURING OUT WHAT DO DO
{
	
}


Customer getCustomerFromUser()//NOT SURE IF IT IS CORRECT
{
	std::string custName;
	std::string custAddress;
	std::cout << "Please enter your name ==> ";
	std::getline(std::cin, custName);
	std::cout << "Please enter your address ==> ";
	std::getline(std::cin, custAddress);

	return Customer(custName, custAddress);
}

int main(void) {
	Quantities ordered = { 0 };
	Customer patron = getCustomerFromUser();
	patron.custInfo(std::cout);

	bool done = false;
	while (!done) {
		displayMenu(patron);
		switch (getCharFromUser("Your selection: ")) {
		case '1':
			loadProductQuantity(AVAILABLE_PRODUCTS[0], ordered);
			break;
		case '2':
			loadProductQuantity(AVAILABLE_PRODUCTS[1], ordered);
			break;
		case '3':
			loadProductQuantity(AVAILABLE_PRODUCTS[2], ordered);
			break;
		case 'X': case 'x':
			done = true;
			break;
		default:
			std::cout << "Invalid selection. Please try again";
			std::cin.get();
			// no break in the default case
		}
	}
	doneShowOrder(patron, ordered);

	return 0;
}

void orderSummary(Quantities ordered) {
	std::cout << std::endl;
	std::cout << "======= ORDER SUMMARY ====" << std::endl;
	std::cout << "Items selected" << std::endl;
	for (int i = 0; i < AVAILABLE_PRODUCTS_COUNT; i++) {
		// only show beverages that has at least one order
		if (ordered[i] > 0) {
			std::cout << "You selcted: " << std::endl;// print something for AVAILABLE_PRODUCTS[i] NOT SURE IF THIS IS CORRECT
		}
	}
}


I need assistance with figuring this out.
What is the code supposed to do?
*Use 2 arrays: one for the products, and one for the quantities.
*Use loops to assign values to the arrays.
*Use loops to read and print values from the arrays.
*Complete the following in your code:
*Provide a list of available products
*Ask the customer to select products and quantities
*Save the provided details in arrays
*Read from the arrays to print the order summary; that is, the products, quantities, and the total price for each product
*Calculate and print the total price for the order

These are the requirements.
Remaining issues.


assignment detail:

Complete the following in your code:

*Provide a list of available products

*Ask the customer to select products and quantities

*Save the provided details in arrays

*Read from the arrays to print the order summary; that is, the products, quantities, and the total price for each product

*Calculate and print the total price for the order

I am getting errors on the following:

line 75 "expected a ')'

line 76 "expected an expression"

line 85 "identifier "beverage" is undefined"

line 85 "identifier "quantities" is undefined"


Along with this what should go into the function
doneShowOrder
:

1
2
3
4
5
void doneShowOrder(const Customer &, Quantities)//NEED HELP FIGURING OUT WHAT DO DO

{

}


These seem to be the only remaining issues I have.

Full 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
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream> // stringstream
#include <cctype> // isalph, isdigit

class Customer {
	const std::string custName, custAddress;
public:
	void custInfo(std::ostream &) const
	{
		std::cout << "Name" << custName << "\n"
			"Address" << custAddress << "\n" << std::endl;
	}
	void custWelcome(std::ostream &) const
	{
		std::cout << "\nHello " << custName << "\nAddress: " << custAddress << std::endl;
	}
	std::string custValue() const
	{
		return custName;
	}

	Customer(const std::string &inputCustName, const std::string &inputCustAddress)
		: custName(inputCustName), custAddress(inputCustAddress)
	{
	}
};

struct Beverage {
	const std::string name;
	double price;

	void bevInfo(std::ostream &) const
	{
		std::cout << "Name" << name << "\n"
			<< "Price" << "$" << price << "\n"
			<< "Total" << "$" << std::endl;
	}
	void bevSelect(std::ostream &) const
	{
		std::cout << "Selection: " << name << ", price per unit: $" << price << std::endl;
	}
	Beverage(const std::string &bevName, double bevPrice)
		: name(bevName), price(bevPrice)
	{
	}
};


const int AVAILABLE_PRODUCTS_COUNT = 3;
const Beverage AVAILABLE_PRODUCTS[AVAILABLE_PRODUCTS_COUNT] = {
	Beverage("Water", 1.45),
	Beverage("Soda", 2.98),
	Beverage("Ice Tea", 3.29)
};

typedef int Quantities[AVAILABLE_PRODUCTS_COUNT];


double totalCost(Quantities);
void orderSummary(Quantities);
//std::string getStringFromUser(const std::string &prompt);
char getCharFromUser(const std::string &prompt);
Customer getCustomerFromUser();
void displayMenu(const Customer &);
void loadProductQuantity(const Beverage &, Quantities);
void doneShowOrder(const Customer &, Quantities);

double totalCost(Quantities)//NOT SURE IF IT IS CORRECT
{
	double totalCost = 0;

	for (int i = 0; i < AVAILABLE_PRODUCTS_COUNT; i++) {
		totalCost += (Quantities*Beverage.bevprice)
	}
	return totalCost;

}

void loadProductQuantity(const Beverage &, Quantities)//NEED HELP FIGURING OUT WHAT DO DO
{
	int Product;

	Product = beverage * quantities;
}

void doneShowOrder(const Customer &, Quantities)//NEED HELP FIGURING OUT WHAT DO DO
{

}

void displayMenu(const Customer &prompt)//NOT SURE IF IT IS CORRECT
{
	std::cout << std::endl << std::endl
		<< &prompt
		<< ", Please select the beverage you would like to purchase from the menu: "
		<< std::endl;

	std::cout << "Drink Menu" << std::endl;
	std::cout << "========" << std::endl;
	std::cout << "1 - Water $1.45" << std::endl;
	std::cout << "2 - Soda $2.98" << std::endl;
	std::cout << "3 - Iced Tea $3.29" << std::endl;
	std::cout << "X - Exit " << std::endl << std::endl;
}

//void getStringFromUser(std::string &prompt)//NEED HELP FIGURING OUT WHAT DO DO
//{

//}

char getCharFromUser(std::string &prompt)//NEED HELP FIGURING OUT WHAT DO DO
{
	char key;

	std::cout << "ENTER THE QUANTITY OF THE PRODUCT OR PRESS X TO EXIT";

	std::cin >> key;

	return key;
}


Customer getCustomerFromUser()//NOT SURE IF IT IS CORRECT
{
	std::string custName;
	std::string custAddress;
	std::cout << "Please enter your name ==> ";
	std::getline(std::cin, custName);
	std::cout << "Please enter your address ==> ";
	std::getline(std::cin, custAddress);

	return Customer(custName, custAddress);
}

int main(void) {
	Quantities ordered = { 0 };
	Customer patron = getCustomerFromUser();
	patron.custInfo(std::cout);

	bool done = false;
	while (!done) {
		displayMenu(patron);
		switch (getCharFromUser("Your selection: ")) {
		case '1':
			loadProductQuantity(AVAILABLE_PRODUCTS[0], ordered);
			break;
		case '2':
			loadProductQuantity(AVAILABLE_PRODUCTS[1], ordered);
			break;
		case '3':
			loadProductQuantity(AVAILABLE_PRODUCTS[2], ordered);
			break;
		case 'X': case 'x':
			done = true;
			break;
		default:
			std::cout << "Invalid selection. Please try again";
			std::cin.get();
			// no break in the default case
		}
	}
	doneShowOrder(patron, ordered);

	return 0;
}

void orderSummary(Quantities ordered) {
	std::cout << std::endl;
	std::cout << "======= ORDER SUMMARY ====" << std::endl;
	std::cout << "Items selected" << std::endl;
	for (int i = 0; i < AVAILABLE_PRODUCTS_COUNT; i++) {
		// only show beverages that has at least one order
		if (ordered[i] > 0) {
			std::cout << "You selcted: " << std::endl;// print something for AVAILABLE_PRODUCTS[i] NOT SURE IF THIS IS CORRECT
		}
	}
}
Last edited on
Topic archived. No new replies allowed.