My Function No Responding When Run

This is my subfunction and I have no idea where is my codes wrong~~
Please help solve~~
Thank You Very Much~~

int add()
{

int x; //types of addtion
int y; //types of y
int amt; // amount
int menu[y][x];
bool cond1 = true;
bool cond2 = true;

cout<<"Which Drink(s) Do You Wish To Order : ";
while(cond1)
{
if(cin>>y)
{
if(y != 0 || y != 1 || y != 2 || y != 3 || y != 4)
{cout<<endl<<"Please Choose Between 1,2,3,4,5!"<<endl;}

else
{
if(y=0)
{cout<<"Expresso\n";}
else if(y=1)
{cout<<"Cappucino\n";}
else if(y=2)
{cout<<"Latte\n";}
else if(y=3)
{cout<<"Hot Chocolate\n";}
else
{cout<<"Plain Tea\n";}
cond1 = false;
}
}
else
{
cin.clear();
cin.ignore(10000,'\n');
cout<<"Please Choose Between 1,2,3,4,5!"<<endl;
cout<<"Which Drink(s) Do You Wish To Order : ";
}
}
cout<<endl<<"Which Addition(s) Do You Wish To Add : ";
while(cond2)
{
if(cin>>x)
{
if(x !=0 || x !=1 || x !=2 || x !=3)
{cout<<endl<<"Please Choose Between 1,2,3,4 !"<<endl;}

else
{
if(x=0)
{cout<<"Regular\n";}
else if(x=1)
{cout<<"Sugar\n";}
else if(x=2)
{cout<<"Milk\n";}
else
{cout<<"Both\n";}
cond2= false;
}
}
}
cout<<"How Many Drink(s) Do You Want : ";
cin>>amt;

menu[y][x] = amt;

return menu[y][x];
}
Hi @quisite in
a quick review i
see that you are using
the assignment operator =
instead of the "Equal to" operator ==

if(y=0)...
Last edited on
Is tat all is the cause tat problem occur?? ~~
thanks
Here's the whole thing in code tags - hopefully a little easier to follow :)

In addition to what eyenrique mentioned about the equality operator, the size of an array needs to be set when the program is compiled, so you can't do something like this int menu[y][x]; with y and x not being defined yet.

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
int add()
{

	int x; //types of addtion
	int y; //types of y
	int amt; // amount
	int menu[y][x];
	bool cond1 = true;
	bool cond2 = true;
	
	cout<<"Which Drink(s) Do You Wish To Order : ";
	while(cond1)
	{
		if(cin>>y)
		{
			if(y != 0 || y != 1 || y != 2 || y != 3 || y != 4)
			{
				cout<<endl<<"Please Choose Between 1,2,3,4,5!"<<endl;
			}
			else
			{
				if(y=0)
				{
					cout<<"Expresso\n";
				}
				else if(y=1)
				{
					cout<<"Cappucino\n";
				}
				else if(y=2)
				{
					cout<<"Latte\n";
				}
				else if(y=3)
				{
					cout<<"Hot Chocolate\n";
				}
				else
				{
					cout<<"Plain Tea\n";
				}
				cond1 = false;
			}
		}
		else
		{
			cin.clear();
			cin.ignore(10000,'\n');
			cout<<"Please Choose Between 1,2,3,4,5!"<<endl;
			cout<<"Which Drink(s) Do You Wish To Order : ";
		}
	}
	cout<<endl<<"Which Addition(s) Do You Wish To Add : ";
	while(cond2)
	{
		if(cin>>x)
		{
			if(x !=0 || x !=1 || x !=2 || x !=3)
			{
				cout<<endl<<"Please Choose Between 1,2,3,4 !"<<endl;
			}
			else
			{
				if(x=0)
				{
					cout<<"Regular\n";
				}
				else if(x=1)
				{
					cout<<"Sugar\n";
				}
				else if(x=2)
				{
					cout<<"Milk\n";
				}
				else
				{
					cout<<"Both\n";
				}
				cond2= false;
			}
		}
	}
	cout<<"How Many Drink(s) Do You Want : ";
	cin>>amt;
	
	menu[y][x] = amt;
	
	return menu[y][x];
}
line 16 and line 58 - you'd want these to be logical ANDs &&, not ORs, ||


and should they be able to enter 1 through 5 or 0 through 4? The numbers you're checking against don't seem to match the message the user gets.
ok thank~~ everything solve~~
@wildblue
@eyenrique

Very Appreciate for you both in helping myself~~
and thank alot to you both~~ ^.^
But Now I have one more question~~

How to return a value from an array

for example now I have an array -> int array[5][4]

and I wish to return the value of array at array[1][4]

what should I do?

Is it -> return array[1][4]; ?
Yes it is;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//return_array_value.cpp
//##

#include <iostream>

using namespace std;

int f();

int main(){

        cout<<f()<<endl;

return 0; //indicates success
}//@end of main

int f(){
        int array[3][3]={1,2,3,4,5,6,7,8,9};

return array[1][1];
}//end function f
5
Thanks @evenrique ,it's work

but now one more question arise~~


If I wish to return array location eg. array[3][2] from subfunction to main, do I

only can reach it by return the value [3] and [2] turn by turn with aid of loops

from subfunction to main?
If I wish to return array location eg. array[3][2] from subfunction to main


array[3][2] is a single value.

it's effectively the same as this:
1
2
    int x = 5;
    return x;


If you are asking, how can you return the entire contents of the array, then perhaps it is simpler to define the array in main() and pass it as a parameter to the other function.
http://www.cplusplus.com/doc/tutorial/arrays/

Oh I See ~~~ Thanks ya @chervil ^.^~~
Topic archived. No new replies allowed.