0

I'm currently taking a class at my high school, that teaches C# and .net framework, python, etc. I have to make a program that plays "Rock, Paper, Scissors" against a person using return-methods as the project for this unit.

I keep running into an error on Microsoft Visual Studios 2015 that says No Overload for method 'PCRandomizer' takes 1 arguments

I'm still really new to this whole system so I'm having a hard time understanding this, but my program (so far) is like this;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Rock__Paper__Scissors
{
    public partial class rockPaperScissors : Form
    {
        public rockPaperScissors()
        {
            InitializeComponent();
        }
    int playerChoice;

    // Variable to indicate what the choice is.
    int pcChoice;

    private int PCRandomizer()
    {


        // Create a Random Object.
        Random rand = new Random();

        // Get the rand integer between 1 and 3.
        // 1 and the PC has chosen Rock.
        // 2 and the PC has chosen Paper.
        // 3 and the PC has chosen scissors.
        pcChoice = rand.Next(1, 3);

        // This returns the value back to the main method.
        return pcChoice;
    }



    private void playerRockPic_Click(object sender, EventArgs e)
    {
        playerChoice = 1;

        PCRandomizer(out pcChoice);
    }

    private void playerPaperPic_Click(object sender, EventArgs e)
    {

    }

    private void playerScissorsPic_Click(object sender, EventArgs e)
    {

    }

    private void resetButton_Click(object sender, EventArgs e)
    {

    }

    private void exitButton_Click(object sender, EventArgs e)
    {
        // Close the Form
        this.Close();
    }
  }
}

I apologize for the long post, but I'm getting pretty desperate as this is already a day behind schedule and several people in my class also have this issue.

I found this page here, but I did not understand it.

Jose Rodriguez
  • 9,753
  • 13
  • 36
  • 52
Ander109
  • 3
  • 1
  • You've defined `PCRandomizer` as taking no arguments. However, you're invoking it: `PCRandomizer(out pcChoice)` with an argument. That's what the error means - it's up to *you* to decide which of the two definitions are correct. However, it's likely you've confused an out parameter with a *return* parameter. You may have wanted to write `pcChoice = PCRandomizer()` – Rob Feb 01 '17 at 02:29
  • Thank you guys so much, both of the responses. – Ander109 Feb 01 '17 at 02:35
  • side note: to save you time waiting for question timer reset - here is answer to your next question you are about to ask - http://stackoverflow.com/questions/4855756/random-number-generation-same-number-returned. Also please read [MCVE] guidance on posting code - sample in the question has way too many unrelated lines. – Alexei Levenkov Feb 01 '17 at 02:59
  • @Ander109 If parameter's answer helped you solve the problem - please mark it as accepted. Thanks! – Rob Feb 01 '17 at 03:23

1 Answers1

3

So instead of using an out, simply set your pcChoice variable to the result of PCRandomizer. That method returns the integer, which will be assigned to pcChoice.

private void playerRockPic_Click(object sender, EventArgs e)
{
    playerChoice = 1;

    pcChoice = PCRandomizer();
}
parameter
  • 614
  • 10
  • 17