为什么我不断重新定义形式参数错误 [英] Why do I keep getting a redefinition of formal parameter error

查看:62
本文介绍了为什么我不断重新定义形式参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream>
using namespace std;
void  mf_option(int player1, int player2);
void  mf_option2(int player1, int player2);
void  mf_option3(int player1, int player2);


int main()
{
    int player1, player2;
    cout << "\n\n\nWlcome to \"Rock Paper Scissor game\"\n";

    cout << " Type 0 for rock, 1 for paper , and 2 for scissors\n";
    cout << "Player 1, choose 0, 1 or 2: ";
    cin >> player1;
    system("clear");
    cout << " Type 0 for rock, 1 for paper , and 2 for scissors\n";
    cout << "Player 2, choose 0, 1 or 2: ";
    cin >> player2;
    system("clear");

    cout << "\n\nplayer 1, you chose " << player1 << " and player 2 you        chose " << player2 << "\n\n";
    mf_option(player1, player2);
    mf_option2(player1, player2);
    mf_option3(player1, player2);
    return 0;
}

void mf_option(int player1, int player2)
{
    int player1, player2;
    if (player1 == 0)
    {
        if (player2 == 0)
            cout << "It's a tie!\n\n\n\n";
        else if (player2 == 1)
            cout << "Paper Beat rock! Player2 wins!\n\n\n\n";
        else if (player2 == 2)
            cout << "Rock beat scissors! Player 1 wins!\n\n\n\n";
    }
}
void mf_option2(int player1, int player2)
{
    int player1, player2;
    if (player1 == 1)
    {
        if (player2 == 0)
            cout << "Paper beat rock! Player 1 wins!\n\n\n\n";
        else if (player2 == 1)
            cout << "It's a tie!\n\n\n\n";
        else if (player2 == 2)
            cout << "Scissors beat paper! Player 2 wins!\n\n\n\n";
    }
}
 void mf_option3(int player1, int player2)
{
    int player1, player2;
if (player1 == 2)
    {
        if (player2 == 0)
            cout << "Rock beat scissors! Player 2 wins!\n\n\n\n";
        else if (player2 == 1)
            cout << "Scissors beat paper! Player 1 wins!\n\n\n\n";
        else if (player2 == 2)
            cout << "its a tie!\n\n\n\n";
    }
}

当我尝试运行该程序时,它说我重新定义了形式参数错误.该错误发生在第35、48、61行.该错误是针对player1和player2的.有人也可以解释一下用户定义函数的重点

when i try to run this program it says that i have a redefinition of formal parameter errors. the error occurs on lines 35, 48, 61. The error is for player1 and player2. can someone also please explain the point of a user defined function

推荐答案

问题在这里:

void mf_option(int player1, int player2)
{
    int player1, player2;
...

您要定义的变量与要传入的变量具有相同的名称.

You are defining variables with the same names as those being passed in.

这篇关于为什么我不断重新定义形式参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆