So I recently did a Rock-Paper-Scissors program but I wanted to experiment and a different way to make the code more convenient. So I thought it would be a good idea to use a function to make all the IFs and else IFs outcome take place. (Ie if the player chooses rock and computer choose paper then computer wins.)
The problem, however, is that when I tried to code it, The program says "warning: control may reach end of non-void function [-Wreturn-type]". Now from what I gathered from the web, that means that their no way for me to return back to the int main() function once it gets to the other function I created. I thought I had fixed it but. Could someone have a look and tell me what I'm doing wrong?
Here the code :
#include <bits/stdc++.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int Player_Wins;
int com_wins;
string computer_choices [3] = {"Rock","Paper","Scissors"};
string Player_Choices [3] = {"Rock","Paper","Scissors"};
bool Game_Over = false;
int GameOutCome(int a,string b)
{
int Player_Choice;
string Computer_Choice;
srand(time(0));
string Picked_Choice = computer_choices[rand() % 3 ];
string Player_Picked_Choice;
a=Player_Choice;
b=Picked_Choice;
if (Player_Choice == 1)
{
Player_Picked_Choice= Player_Choices[0];
if (Player_Picked_Choice== Player_Choices[0] and Picked_Choice==computer_choices [1])
{
cout<< "You have chosen " << Player_Picked_Choice <<endl;
cout<<"\n"<<endl;
cout<< "The Computer have chosen "<< Picked_Choice <<endl;
cout<< "The computer wins the round."<<endl;
return com_wins++;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<<
com_wins<<endl;
cout<<"\n"<<endl;
if (Player_Wins ==3|| com_wins ==3)
{
Game_Over= true;
if(Game_Over == true)
{
cout<<"The game is over!!!"<<endl;
}
}
}
}
else if (Player_Picked_Choice== Player_Choices[0] and
Picked_Choice==computer_choices[0])
{
cout<<"You have chosen "<< Player_Picked_Choice <<endl;
cout<<"\n"<<endl;
cout<<" The Computer have chosen "<< Picked_Choice<<endl;
cout<<"\n"<<endl;
cout <<"It's a tie."<<endl;
}
else if (Player_Picked_Choice== Player_Choices[0] and
Picked_Choice==computer_choices[2])
{
cout<< "You have chosen "<< Player_Picked_Choice <<endl;
cout<< " The Computer have chosen"<< Picked_Choice <<endl;
cout<<"You won the round."<<endl;
return Player_Wins++;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<<
com_wins<<endl;
cout<<"\n"<<endl;
if (Player_Wins ==3|| com_wins ==3)
{
Game_Over= true;
if(Game_Over == true)
{
cout<<"The game is over!!!"<<endl;
}
}
}
}
else if (Player_Choice == 2)
{
Player_Picked_Choice= Player_Choices[1];
if (Player_Picked_Choice== Player_Choices[1] and Picked_Choice==computer_choices [2])
{
cout<< "You have chosen "<< Player_Picked_Choice << " The Computer have chosen "<<
Picked_Choice <<endl;
cout<< "The computer wins the round." <<endl;
return com_wins++;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<<
com_wins<<endl;
cout<<"\n"<<endl;
if (Player_Wins ==3|| com_wins ==3)
{
Game_Over= true;
if(Game_Over == true)
{
cout<<"The game is over!!!"<<endl;
return 0;
}
}
}
else if (Player_Picked_Choice== Player_Choices[1] and
Picked_Choice==computer_choices[1])
{
cout<< "You have chosen "<< Player_Picked_Choice <<endl;
cout<<"\n"<<endl;
cout<< "The Computer have chosen "<< Picked_Choice <<endl;
cout<<" It's a tie."<<endl;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<<
com_wins<<endl;
}
else if (Player_Picked_Choice== Player_Choices[1] and
Picked_Choice==computer_choices[0])
{
cout<< "You have chosen "<< Player_Picked_Choice <<endl;
cout<<"\n"<<endl;
cout<< " The Computer have chosen "<< Picked_Choice <<endl;
cout<<" You won the round."<<endl;
return Player_Wins++;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<<
com_wins<<endl;
cout<<"\n"<<endl;
if (Player_Wins ==3|| com_wins ==3)
{
Game_Over= true;
if(Game_Over == true)
{
cout<<"The game is over!!!"<<endl;
return 0;
}
}
}
}
else if (Player_Choice == 3)
{
Player_Picked_Choice= Player_Choices[2];
if (Player_Picked_Choice== Player_Choices[2] and Picked_Choice==computer_choices [0])
{
cout<< "You have chosen "<< Player_Picked_Choice<<endl;
cout<<"\n"<<endl;
cout<<" The Computer have chosen "<< Picked_Choice <<endl;
cout<< " The computer wins the round."<<endl;
return com_wins++;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<<
com_wins<<endl;
cout<<"\n"<<endl;
if (Player_Wins ==3|| com_wins ==3)
{
Game_Over= true;
if(Game_Over == true)
{
cout<<"The game is over!!!"<<endl;
return 0;
}
}
}
else if (Player_Picked_Choice== Player_Choices[2] and
Picked_Choice==computer_choices[2])
{
cout<< "You have chosen "<< Player_Picked_Choice <<endl;
cout<<"\n"<<endl;
cout<<" The Computer have chosen "<< Picked_Choice <<endl;
cout<<" It's a tie."<<endl;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<<
com_wins<<endl;
return a;
}
else if (Player_Picked_Choice== Player_Choices[2] and
Picked_Choice==computer_choices[1])
{
cout<< "You have chosen "<< Player_Picked_Choice <<endl;
cout<<"\n"<<endl;
cout<< " The Computer have chosen \n"<< Picked_Choice <<endl;
cout<<" You won the round."<<endl;
return Player_Wins++;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<<
com_wins<<endl;
cout<<"\n"<<endl;
}
}
}
int main()
{
cout<<"Welcome to Rock, Paper Scissors!!"<<endl;
while (Player_Wins !=3 || com_wins != 3)
{
int Player_Choice;
cout<<"\n"<<endl;
cout<<"First to three wins. \n To pick rock, press 1\n To pick paper, press 2 \n To pick
scissors, Press 3"<<endl;
cout<<"\n"<<endl;
cout<<"Please make a choice: ";cin>>Player_Choice;
string Picked_Choice = computer_choices[rand() % 3 ];
cout<<"\n"<<endl;
GameOutCome(Player_Choice,Picked_Choice);
if (Player_Wins ==3|| com_wins ==3)
{
Game_Over= true;
if(Game_Over == true)
{
cout<<"The game is over!!!"<<endl;
}
}
}
if (Player_Wins==3)
{
cout<<" The Player Wins!!"<< endl;
}
else if (com_wins==3)
{
cout<< "The Computer Wins!!"<<endl;
}
return 0;
}
EDIT: Update 12/29/19
Okay so I got the code working to the point to where it gives you the choice but thats it. What else am I going wrong?
#include <bits/stdc++.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int Player_Wins;
int com_wins;
string computer_choices [3] = {"Rock","Paper","Scissors"};
string Player_Choices [3] = {"Rock","Paper","Scissors"};
bool Game_Over = false;
int GameOutCome(int a,string b)
{
int Player_Choice;
srand(time(0));
string Picked_Choice = computer_choices[rand() % 3 ];
string Player_Picked_Choice;
a=Player_Choice;
b=Picked_Choice;
if (Player_Choice == 1)
{
Player_Picked_Choice= Player_Choices[0];
if (Player_Picked_Choice== Player_Choices[0] and Picked_Choice==computer_choices [1])
{
cout<< "You have chosen " << Player_Picked_Choice <<endl;
cout<<"\n"<<endl;
cout<< "The Computer have chosen "<< Picked_Choice <<endl;
cout<< "The computer wins the round."<<endl;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<< com_wins<<endl;
cout<<"\n"<<endl;
return com_wins++;
if (Player_Wins ==3|| com_wins ==3)
{
Game_Over= true;
if(Game_Over == true)
{
cout<<"The game is over!!!"<<endl;
return 0;
}
return a;
}
return a;
}
else if (Player_Picked_Choice== Player_Choices[0] and Picked_Choice==computer_choices[0])
{
cout<<"You have chosen "<< Player_Picked_Choice <<endl;
cout<<"\n"<<endl;
cout<<" The Computer have chosen "<< Picked_Choice<<endl;
cout<<"\n"<<endl;
cout <<"It's a tie."<<endl;
return 0;
}
else if (Player_Picked_Choice== Player_Choices[0] and Picked_Choice==computer_choices[2])
{
cout<< "You have chosen "<< Player_Picked_Choice <<endl;
cout<< " The Computer have chosen"<< Picked_Choice <<endl;
cout<<"You won the round."<<endl;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<< com_wins<<endl;
cout<<"\n"<<endl;
return Player_Wins++;
if (Player_Wins ==3|| com_wins ==3)
{
Game_Over= true;
if(Game_Over == true)
{
cout<<"The game is over!!!"<<endl;
return 0;
}
return 0;
}
return 0;
}
return 0;
}
else if (Player_Choice == 2)
{
Player_Picked_Choice= Player_Choices[1];
if (Player_Picked_Choice== Player_Choices[1] and Picked_Choice==computer_choices [2])
{
cout<< "You have chosen "<< Player_Picked_Choice << " The Computer have chosen "<< Picked_Choice <<endl;
cout<< "The computer wins the round." <<endl;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<< com_wins<<endl;
cout<<"\n"<<endl;
return com_wins++;
if (Player_Wins ==3|| com_wins ==3)
{
Game_Over= true;
if(Game_Over == true)
{
cout<<"The game is over!!!"<<endl;
return 0;
}
return 0;
}
return 0;
}
else if (Player_Picked_Choice== Player_Choices[1] and Picked_Choice==computer_choices[1])
{
cout<< "You have chosen "<< Player_Picked_Choice <<endl;
cout<<"\n"<<endl;
cout<< "The Computer have chosen "<< Picked_Choice <<endl;
cout<<" It's a tie."<<endl;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<< com_wins<<endl;
return a;
}
else if (Player_Picked_Choice== Player_Choices[1] and Picked_Choice==computer_choices[0])
{
cout<< "You have chosen "<< Player_Picked_Choice <<endl;
cout<<"\n"<<endl;
cout<< " The Computer have chosen "<< Picked_Choice <<endl;
cout<<" You won the round."<<endl;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<< com_wins<<endl;
cout<<"\n"<<endl;
return Player_Wins++;
if (Player_Wins ==3|| com_wins ==3)
{
Game_Over= true;
if(Game_Over == true)
{
cout<<"The game is over!!!"<<endl;
return 0;
}
return 0;
}
return 0;
}
return 0;
}
else if (Player_Choice == 3)
{
Player_Picked_Choice= Player_Choices[2];
return a;
if (Player_Picked_Choice== Player_Choices[2] and Picked_Choice==computer_choices [0])
{
cout<< "You have chosen "<< Player_Picked_Choice<<endl;
cout<<"\n"<<endl;
cout<<" The Computer have chosen "<< Picked_Choice <<endl;
cout<< " The computer wins the round."<<endl;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<< com_wins<<endl;
cout<<"\n"<<endl;
return com_wins++;
if (Player_Wins ==3|| com_wins ==3)
{
Game_Over= true;
if(Game_Over == true)
{
cout<<"The game is over!!!"<<endl;
return 0;
}
return 0;
}
return 0;
}
else if (Player_Picked_Choice== Player_Choices[2] and Picked_Choice==computer_choices[2])
{
cout<< "You have chosen "<< Player_Picked_Choice <<endl;
cout<<"\n"<<endl;
cout<<" The Computer have chosen "<< Picked_Choice <<endl;
cout<<" It's a tie."<<endl;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<< com_wins<<endl;
return 0;
}
else if (Player_Picked_Choice== Player_Choices[2] and Picked_Choice==computer_choices[1])
{
cout<< "You have chosen "<< Player_Picked_Choice <<endl;
cout<<"\n"<<endl;
cout<< " The Computer have chosen \n"<< Picked_Choice <<endl;
cout<<" You won the round."<<endl;
cout<<"\n"<<endl;
cout<<"The score is: \n Player: "<< Player_Wins << "\n Computer : "<< com_wins<<endl;
cout<<"\n"<<endl;
return Player_Wins++;
}
return 0;
}
return 0;
}
int main()
{
cout<<"Welcome to Rock, Paper Scissors!!"<<endl;
while (Player_Wins !=3 || com_wins != 3)
{
int Player_Choice;
cout<<"\n"<<endl;
cout<<"First to three wins. \n To pick rock, press 1\n To pick paper, press 2 \n To pick scissors, Press 3"<<endl;
cout<<"\n"<<endl;
cout<<"Please make a choice: ";cin>>Player_Choice;
string Picked_Choice = computer_choices[rand() % 3 ];
cout<<"\n"<<endl;
GameOutCome(Player_Choice,Picked_Choice);
if (Player_Wins ==3|| com_wins ==3)
{
Game_Over= true;
if(Game_Over == true)
{
cout<<"The game is over!!!"<<endl;
}
}
}
if (Player_Wins==3)
{
cout<<" The Player Wins!!"<< endl;
}
else if (com_wins==3)
{
cout<< "The Computer Wins!!"<<endl;
}
return 0;
}