help with C++
I hope someone can help me. I'm doing a class project, and I'm pretty new to computer programming. I need to create a rock paper scissors game (Not quite the style of majority of games on here) and I can't get past these two errors
error C2660: 'convertObject' : function does not take 1 arguments (Line 126)
error C2660: 'convertObject' : function does not take 1 arguments (Line 129)
my code is as follows:
/* The code in this program produces a game of "Rock, Paper, Scissors".
Player 1 enters r or R for Rock, s or S for Scissors, or p or P for
Paper. Then Player 2 makes his/her selection. The program determines
and displays the winner. Rock beats (crush) Scissors, Scissors beat (cut) Paper,
and Paper beats (covers) Rock. */
//Header Files
# include <iostream>
# include <string>
# include <cstdlib>
using namespace std;
// This creates a user defined data type
enum object {Rock, Paper, Scissors};
//function prototypes
void printstars();
void gameDescription();
int convertObject();
int assignChoice (char);
//global variables
object selection1;
object selection2;
char choice1;
char choice2;
int code;
int main()
{
//declare local variables
char response;
int play1;
int play2;
string winner;
gameDescription();
cout << "Would you like to play? y/n" << endl;
cin >> response;
while (response == 'Y' || response == 'y'|| response == 'Yes' || response == 'yes')//Display input info
{
cout << endl;
cout << "Player 1" << endl;
cout << "Enter:" << endl;
cout << "R/r for rock:" << endl;
cout << "P/p for paper:" << endl;
cout << "S/s for scissors:" << endl;
cout << endl;
cin >> choice1;
switch (choice1)
{
case 'R':
case 'r':
selection1 = Rock;
break;
case 'P':
case 'p':
selection1 = Paper;
break;
case 'S':
case 's':
selection1 = Scissors;
break;
}
play1 = assignChoice(choice1); //call function to assign a numeric value to the selection
system("cls");
cout << endl;
cout << "Player 2" << endl;
cout << "Enter:" << endl;
cout << "R/r for rock:" << endl;
cout << "P/p for paper:" << endl;
cout << "S/s for scissors:" << endl;
cout << endl;
cout << endl;
cin >> choice2;
switch (choice2)
{
case 'R':
case 'r':
selection2 = Rock;
break;
case 'P':
case 'p':
selection2 = Paper;
break;
case 'S':
case 's':
selection2 = Scissors;
break;
}
play2 = assignChoice(choice2); //call function to assign a numeric value to the selection
if (play1 == 1 && play2 == 3 ||play1 == 2 && play2 == 1 || play1 == 3 && play2 == 2)
{
winner = "Player 1";
}
if (play2 == 1 && play1 == 3 || play2 == 2 && play1 == 1 || play2 == 3 && play1 == 2)
{
winner = "Player 2";
}
if (play1 == 1 && play2 == 1 || play1 == 2 && play2 == 2 || play1 == 3 && play2 == 3)
winner = "no one";
system("cls");
//Output selections and winner
cout << "Player 1 selected ";
play1 = convertObject(selection1);
cout << endl;
cout << "Player 2 selected ";
play2 = convertObject(selection2);
cout << "." << endl;
cout << endl;
cout << "The winner is " << winner << "." << endl;
cout << endl;
cout << "Would you like to play again? (y/n)? ";
cin >> response;
}
return 0;
}
int assignChoice(char choice)//function to assign numeric values to selection to make comparison easier
{
if (choice == 'r' || choice == 'R')
choice = 1;
if (choice == 'p' || choice == 'P')
choice = 2;
if (choice == 's' || choice =='S')
choice = 3;
return choice;
}
int convertObject(object selection) //function to allow the selections to be displayed
{
switch (selection)
{
case 1:
cout << "Rock";
break;
case 2:
cout << "Paper";
break;
case 3:
cout << "Scissors";
break;
}
return code;
}
void printstars()
{
cout << "*****************************************************************" << endl;
cout << "*****************************************************************" << endl;
}
void gameDescription()
{
printstars();
cout << endl;
cout << " ROCK, PAPER, SCISSORS " << endl;
cout << endl;
printstars();
cout << endl;
}
Your declaration for "convertObject" is this:
Your implementation is this:
Can you see the problem?
One solution is not to declare convertObject at all. Instead, move the implementation to the top of the file. A function implementation (also called the definition) doubles as a declaration, so functions that follow it will be able to call it.
For future note, you posted in the .Net forum. This forum is not for C++, it is for .Net technologies. A better place would be the "For Beginners" forum.
Good Luck! [smile]
int convertObject();
Your implementation is this:
int convertObject(object selection) //function to allow the selections to be displayed{ switch (selection) { case 1: cout << "Rock"; break; case 2: cout << "Paper"; break; case 3: cout << "Scissors"; break; } return code;}
Can you see the problem?
One solution is not to declare convertObject at all. Instead, move the implementation to the top of the file. A function implementation (also called the definition) doubles as a declaration, so functions that follow it will be able to call it.
For future note, you posted in the .Net forum. This forum is not for C++, it is for .Net technologies. A better place would be the "For Beginners" forum.
Good Luck! [smile]
Moving to For Beginners.
Keep in mind that since this is a homework/classwork question, direct answers should not be provided. Instead provide guidance, direction and suggestions -- but nothing that would be essentially copy-pastable. We don't do homework here; rip-off's post is a good example of the kind of answers that should be given.
If you have further questions, cindo, you can ask. Try to be specific about what you want to know and what you have tried or currently understand.
Keep in mind that since this is a homework/classwork question, direct answers should not be provided. Instead provide guidance, direction and suggestions -- but nothing that would be essentially copy-pastable. We don't do homework here; rip-off's post is a good example of the kind of answers that should be given.
If you have further questions, cindo, you can ask. Try to be specific about what you want to know and what you have tried or currently understand.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement