Calling functions in main.

I made some functions outside of the main and I want to call it back in the main.

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
class Pizza
{
	private:
		  int type;
		  int size;
		  bool cheese;    
		  bool pepperoni; 
  
	public:
		  Pizza();
		  int getType();
		  int getSize();
		  bool getCheese();
		  bool getPepperoni();
		  void setType(int t);
		  void setSize(int s);
		  void setCheese(bool choice);
		  void setPepperoni(bool choice);

  void outputDescription();
  double computePrice();
};

class Order
{
private:
	vector<Pizza> c; 

public:
	Order();
	void customerOrder();
	void customerTotal();
	void customerinput();
};

...

Order custmizedTotal;
Pizza myPizza;  
bool done=false;
void Order::customerinput(){
while ( again == "y"){	
		cout << "What sized pizza, please enter S, M OR L: ";
		cin >> pSize;
		cin.clear();

		switch(pSize)
		{
			case 'S': case 's':
			size = SMALL; break;
			case 'M': case 'm':
			size = MEDIUM; break;
			case 'L': case 'l':
			size = LARGE; break;
		}

		cout << "What type of pizza, enter D for Deepdish, H for Hand tossed, and P for Pan: ";
		cin >> pType;
		cin.clear();

		switch(pType)
		{
			case 'D': case 'd':
			type = DEEPDISH; break;
			case 'H': case 'h':
			type = HANDTOSSED; break;
			case 'P': case 'p':
			type = PAN; break;
		}

		myPizza.setSize(size);
		myPizza.setType(type);

		cout << "Would you like cheese (y/n)? ";
		cin >> topping;
		cin.clear();

  		if (topping == 'Y' || topping == 'y')
    		myPizza.setCheese(true);

		cout << "Would you like pepperoni (y/n)? ";
		cin >> topping;
		cin.clear();

		if (topping == 'Y' || topping == 'y')
    		myPizza.setPepperoni(true);
    
	  cout << endl
	   << "Your order: ";
	  myPizza.outputDescription();
	  cout << endl;
	  cout << "Price: $" << myPizza.computePrice() << endl;
	  
	  cout << "Again? (y/n)";
	  cin >> again;    
	}
        }
 
Order::Order(){
double total = 0;	
}


void Order::customerTotal(){

	cout << "Your Total order is: " << endl;
	for(int i=0; i<c.size(); i++)
	{ 
		c[i].outputDescription();
		cout << endl;
		cout << c[i].computePrice();
		cout << endl;
		total=total+c[i].computePrice();
	}		
	cout << "Totat Cost: $" << total;
	cout << endl;
	c.push_back(myPizza);
}


The main
1
2
3
4
5
6
7
8
9
int main()
{
	
	custmizedTotal.customerinput();
	if(again != "y"){
	custmizedTotal.customerinput();
	}
	return 0;
}


The code compiles, but doesn't show anything when run.
Last edited on
Just post your whole code please....
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#include <iostream>
#include<string>
#include <vector>
using namespace std;

string again;
char pType, pSize, topping, temp;
const int SMALL = 1;
int type = 0, size = 0;
const int MEDIUM = 2;
const int LARGE = 3;
const int DEEPDISH = 1;
const int HANDTOSSED = 2;
const int PAN = 3;
double total = 0;

class Pizza
{
	private:
		  int type;
		  int size;
		  bool cheese;    
		  bool pepperoni; 
  
	public:
		  Pizza();
		  int getType();
		  int getSize();
		  bool getCheese();
		  bool getPepperoni();
		  void setType(int t);
		  void setSize(int s);
		  void setCheese(bool choice);
		  void setPepperoni(bool choice);

  void outputDescription();
  double computePrice();
};

class Order
{
private:
	vector<Pizza> c; 

public:
	Order();
	void customerOrder();
	void customerTotal();
	void customerinput();
};

Pizza::Pizza()
{
  type = DEEPDISH;
  size = SMALL;
  cheese = pepperoni = false;
}

int Pizza::getType()
{
  return type;
}

int Pizza::getSize()
{
  return size;
}

bool Pizza::getCheese()
{
  return cheese;
}

bool Pizza::getPepperoni()
{
  return pepperoni;
}

void Pizza::setType(int t)
{
  type = t;
}

void Pizza::setSize(int s)
{
  size = s;
}

void Pizza::setCheese(bool choice)
{
  cheese = choice;
}

void Pizza::setPepperoni(bool choice)
{
  pepperoni= choice;
}

void Pizza::outputDescription()
{
  switch (size)
  {
	  case SMALL:
	    cout << "Small "; break;
	  case MEDIUM:
	    cout << "Medium "; break;
	  case LARGE:
	    cout << "Large "; break;
	  default:
	    cout << "Unknown" ;
  }

  switch (type)
  {
	  case DEEPDISH:
	    cout << "deepdish "; break;
	  case HANDTOSSED:
	    cout << "hand tossed "; break;
	  case PAN:
	    cout << "pan "; break;
	  default:
	    cout << "Unknown";
  }

  cout << "pizza";
}

double Pizza::computePrice()
{
  double cost = 0.0;
  switch (size)
  {
  case SMALL:
    cost += 10; break;
  case MEDIUM:
    cost += 14; break;
  case LARGE:
    cost += 17; break;
  }

  if (cheese)
    cost += 2.0;
  if (pepperoni)
    cost += 2.0;

  return cost;
}

Order custmizedTotal;
Pizza myPizza;  
bool done=false;
void Order::customerinput(){
while ( again == "y"){	
		cout << "What sized pizza, please enter S, M OR L: ";
		cin >> pSize;
		cin.clear();

		switch(pSize)
		{
			case 'S': case 's':
			size = SMALL; break;
			case 'M': case 'm':
			size = MEDIUM; break;
			case 'L': case 'l':
			size = LARGE; break;
		}

		cout << "What type of pizza, enter D for Deepdish, H for Hand tossed, and P for Pan: ";
		cin >> pType;
		cin.clear();

		switch(pType)
		{
			case 'D': case 'd':
			type = DEEPDISH; break;
			case 'H': case 'h':
			type = HANDTOSSED; break;
			case 'P': case 'p':
			type = PAN; break;
		}

  
		myPizza.setSize(size);
		myPizza.setType(type);

		cout << "Would you like cheese (y/n)? ";
		cin >> topping;
		cin.clear();

  		if (topping == 'Y' || topping == 'y')
    		myPizza.setCheese(true);

		cout << "Would you like pepperoni (y/n)? ";
		cin >> topping;
		cin.clear();

		if (topping == 'Y' || topping == 'y')
    		myPizza.setPepperoni(true);
    

	  cout << endl
	   << "Your order: ";
	  myPizza.outputDescription();
	  cout << endl;
	  cout << "Price: $" << myPizza.computePrice() << endl;
	  
	  cout << "Again? (y/n)";
	  cin >> again;
	  
	  
	}
}
 
Order::Order(){
double total = 0;	
}


void Order::customerTotal(){

	cout << "Your Total order is: " << endl;
	for(int i=0; i<c.size(); i++)
	{ 
		c[i].outputDescription();
		cout << endl;
		cout << c[i].computePrice();
		cout << endl;
		total=total+c[i].computePrice();
	}		
	cout << "Totat Cost: $" << total;
	cout << endl;
	c.push_back(myPizza);
}


int main()
{
	
	custmizedTotal.customerinput();
	//Order.customerinput(); 
	if(again != "y"){
	custmizedTotal.customerinput();
	}
	return 0;
}	
You haven't initialized again.
Ah! Thank you.
Topic archived. No new replies allowed.