0

i want to return 2 values but i don't know how i can do that. this is part of what i have done, i want to have choice[0] and also choice[1] be returned. also how can i store them in 2 different variables in the main.

int pick()
{
 choice1=wake();
 do
 {
 switch (choice1)
 {
 case 2:
	 homework();
	 choice[0]=2;
	 c=2;
  break;
 case 3: 
	 choice[1]=sleep();
	 choice1=choice[1];
	 choice[0]=3;
	 c++;
	 break;
 case 1:
	choice[1]=wander();
	 choice[0]=1;
	 c=2;
  break;
 default:
	 cout<<"Ha Ha Ha Ha Ha"<<endl;
	 c++;
	 break;
 }
 }
 while(c<2);
 return choice[0];
}

int main()
{
 choice[0]=pick();
 return 0;
}
3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by invisal
0

Your code make no sense. You didn't declare choice[] and choice1 anywhere, how can you use those variable? You cannot return 2 values, but you can return in array.

0

i said that this was part of my code, it works but i just wanted to know how to return 2 values, how can i return in array

0
int pick()
{
 choice1=wake();
 do {
   ........
   .......
  }
 }
 while(c<2);
 [B]return choice[0];[/B]
}

int main()
{
 [B]choice[0]=pick();[/B]
 return 0;
}

First, you didn't declare the choice[] in the function pick(), so choice[] must be declare globally. so if you make change the choice[] in the function, it affect globally. So what's the point of return?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.