qualified-id error.

I'm trying to get this code to calculate the types of pizza ordered and the total cost when "again" is != y but I keep getting these two errors.

[Error] qualified-id in declaration before '(' token (in line 88)
Error] 'customer' was not declared in this scope (line 90)
I'm not to sure where I should define customer, I thought I already did in the private class.

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
#include <iostream>
#include<string>
#include <vector>
using namespace std;

string again;
const int SMALL = 1;
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> customer(); 

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


// code for setting booleans, etc. are here. I'll skip over it. Here's the rest.

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
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;
}


int main()
{
  char pType, pSize, topping, temp;
  int type = 0, size = 0;
  
  while (1){	
  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;
  }

  Pizza myPizza;
  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;
		
	 	if(again == "y")
		{}
		if(again != "y")
		{
			void Order::customerTotal();
			cout << "Your Total order is: " << endl;
			for(int i=0; i<customer.size(); i++)
			{ 
			customer[i].outputDescription();
			cout << endl;
			cout << customer[i].computePrice();
			cout << endl;
			total=total+customer[i].computePrice();
		    }
		    cout << "Totat Cost: $" << total;
		    cout << endl;
			
		}
		break;
		}
		  return 0;
	}
Last edited on
You can try this :
while(again=='y')
{
//.....
}
And put the total order function outside the while loop. Else it will be called everytime one loop ends.
Also did you create an Order object,or are you just placing the function body inside the main function??pls reply on wht u want to do.
The assignment is to:

Create an order class that contains a private vector of type Pizza. This class represents a customer's entire order, where the order may consist of multiple pizzas. Include appropriate functions so that a user of the order class can add pizzas to the order. Also, write a function that outputs everything in the order along with the total price. Write a suitable test program that adds multiple pizzas to an order(s).

Yes i'm trying to create a order object, but I'm to sure sure about where it goes for the assignment.
I took the void order::customerTotal out of the main, and applied the while(again == "y"). Now I have the errors:

[Error] qualified-id in declaration before '(' token (line 65)
[Error] expected '}' at end of input (line 80)
[Error] expected '}' at end of input

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
int main()
{
  char pType, pSize, topping, temp;
  int type = 0, size = 0;
  
  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;
  }

  Pizza myPizza;
  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;
  break;
}
			if(again != "y"){
			void Order::customerTotal(){
			cout << "Your Total order is: " << endl;
			for(int i=0; i<customer.size(); i++)
			{ 
			customer[i].outputDescription();
			cout << endl;
			cout << customer[i].computePrice();
			cout << endl;
			total=total+customer[i].computePrice();
		        }
		        cout << "Totat Cost: $" << total;
		        cout << endl;
		       }
	               }		
		  return 0;
	}
Type this:
1
2
3
4
5
6
7
bool done=false;
char again='y';
Pizza p;
Order r;
while(again=='y')
{....}
r.customerTotal();

Place the class objects outside the while loop also,or you will be recreating them over n over again.
And place the function body in a .cpp file and call the class' member function through a function call.
Your line 81-82 does the rest for you. And forget the "done" variable.
[Error] expected unqualified-id before 'if' (line 15)

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
int main()
{
char pType, pSize, topping, temp;
int type = 0, size = 0;
bool done=false;
char again='y';
Pizza p;
Order r;
while ( again == 'y')
{...}
r.customerTotal();
 return 0;
}

	if(again != 'y'){
			void Order::customerTotal(){
			cout << "Your Total order is: " << endl;
			for(int i=0; i<customer.size(); i++)
			{ 
			customer[i].outputDescription();
			cout << endl;
			cout << customer[i].computePrice();
			cout << endl;
			total=total+customer[i].computePrice();
		        }
		        cout << "Totat Cost: $" << total;
		        cout << endl;
			}
	}


Srry,i didnt see your third post.
Ok, all you need to do is put line 35(in your third post) outside your while loop.
//Pizza myPizza;
Rest will be fine.
And place lines 65-77 in a function body with the same name.
Like this:
1
2
3
4
void Order::customerTotal()
{ cout << "Your Total order is: " << endl; for(int i=0; i<customer.size(); i++) { customer[i].outputDescription(); cout << endl; cout << customer[i].computePrice(); cout << endl; total=total+customer[i].computePrice(); } cout << "Totat Cost: $" << total; cout << endl; }
//and when the action comes this
myOrder.customerTotal();

Here myOrder is an object of Ordrr class.
Hope tht helps.
You Cant Type anything outside main Especially after you type return 0. Period.
Place the if(...) inside the main function.
And if you may, follow the tutorials.
http://www.cplusplus.com/doc/
Yeah I thought that was the case. I'll look over the tutorials.
When I put the function body outside the loop and inside the main, and the old errors return from my 3rd post.

[Error] qualified-id in declaration before '(' token (line 65)
[Error] expected '}' at end of input (line 80)
[Error] expected '}' at end of input
Okay I changed up the code making more functions and changing up the order. Now I have the error:

[Error] expected unqualified-id before '.' token
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
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();
};

//boolean code, etc. Skipped over. Here's the rest.
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
Order custmizedTotal;
Pizza myPizza;  
bool done=false;
void Order::customerinput(){
while(again=="y") {...} }

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(){
       Order.customerinput(); //error is here
       if(again != "y"){
                custmizedTotal.customerTotal(); 
       }
	return 0;
}	
Last edited on
2nd snippet line 23: Order is your class name. You can't call a function by simply specifying the class name. You can only call a member function of a class by referencing an instance of the class. Did you mean customizedTotal?
I've tried that and I would get the error
[Error] ld returned 1 exit status.
With the message: undefined reference to `Order::Order()'
Line 41: You declared a default constructor for Order. Where is your implementation? The error message is telling you the linker can not find the implementation of your default constructor.

I put
1
2
3
Order::Order(){
double total = 0;	
}

And now it runs, but it's not waiting for user input.
Last edited on
Topic archived. No new replies allowed.