为什么我不能使用函数返回值作为参数?

时间:2016-10-26 00:37:41

标签: c function enums parameters

以下是我遇到问题的代码。

if([indexPath row]==2){
      [cell setUserInteractionEnabled:NO];//Here I set disable Could be the problem caused by this??
}
else{
      [cell setUserInteractionEnabled:YES];
}

我需要使用枚举类型来获取每个玩家的输入。 这是一个简单的摇滚,剪刀游戏。 我的输出函数类型有问题,我在函数调用中遇到以下错误,以及在函数体中指定Choice p1choice时。

#include <stdio.h>

int getplayerone (void);
int getplayertwo (void);
void output (int getplayerone (), int getplayertwo ());

enum choice
{ r, p, s };
typedef enum choice Choice;

int
main (int argc, char *argv[])
{
  //getplayerone();
  // getplayertwo();
  output (getplayerone (), getplayertwo ());
  return 0;
}

int
getplayerone (void)
{
  char choice1;
  int choice1int;
  printf ("Player-1 it is your turn!\n");
  printf ("Please enter your choice (p)aper, (r)ock, ir (s)cissors: ");
  scanf (" %c", &choice1);
  if (choice1 == 'r' || choice1 == 'R')
    {
      choice1int = 0;
    }
  else if (choice1 == 'p' || choice1 == 'P')
    {
      choice1int = 1;
    }
  else if (choice1 == 's' || choice1 == 'S')
    {
      choice1int = 2;
    }
  if (choice1int == 0)
    {

    }

  return choice1int;
}

int
getplayertwo (void)
{
  char choice2;
  int choice2int;
  printf ("\nPlayer-2 it is your turn!\n");
  printf ("Please enter your choice (p)aper, (r)ock, ir (s)cissors: ");
  scanf (" %c", &choice2);
  if (choice2 == 'r' || choice2 == 'R')
    {
      choice2int = 0;
    }
  else if (choice2 == 'p' || choice2 == 'P')
    {
      choice2int = 1;
    }
  else if (choice2 == 's' || choice2 == 'S')
    {
      choice2int = 2;
    }

  return choice2int;
}

void
output (int getplayerone (), int getplayertwo ())
{

  Choice p1choice = getplayerone ();
  Choice p2choice = getplayertwo ();

  if (p1choice == r && p2choice == r)
    {
      printf ("Draw");
    }
  else if (p1choice == r && p2choice == p)
    {
      printf ("Player 2 wins");
    }
  else if (p1choice == r && p2choice == s)
    {
      printf ("Player 1 wins");
    }
  else if (p1choice == s && p2choice == r)
    {
      printf ("Player 2 wins");
    }
  else if (p1choice == s && p2choice == p)
    {
      printf ("Player 1 wins");
    }
  else if (p1choice == s && p2choice == s)
    {
      printf ("Draw");
    }
  else if (p1choice == p && p2choice == r)
    {
      printf ("Player 1 wins");
    }
  else if (p1choice == p && p2choice == p)
    {
      printf ("Draw");
    }
  else if (p1choice == p && p2choice == s)
    {
      printf ("Player 2 wins");
    }

  printf ("%d", p1choice);
}

感谢您的输入和帮助!

2 个答案:

答案 0 :(得分:1)

以这种方式调用输出:

output( getplayerone(),  getplayertwo());

用函数本身调用它:

output( getplayerone,  getplayertwo);

答案 1 :(得分:0)

函数原型是错误的,它应该是

void output(int playerone, int playertwo);