tuteja1986
Diamond Member
- Jun 1, 2005
- 3,676
- 0
- 0
yo :! Here is full rewritten C++ program with function : )
Anyways... spend some time making it look good
#include <iostream>
#include <string>
using namespace std;
// Function Prototype
void menu(void);
void game(void);
void rule(void);
void exit(void);
int main() {
menu();
return 0;
}
void menu(void) {
int input;
cout << "########################################################" << endl;
cout << "##############---Rock-Paper-Scissors---#################" << endl;
cout << "########################################################" << endl;
cout << "MENU :" << endl;
cout << "1. Play Rock-Paper-Scissors" << endl;
cout << "2. Game Rule" << endl;
cout << "3. Exit " << endl;
cout << "" << endl;
cout <<"Selection: ";
cin >> input;
switch ( input ) {
case 1:
game();
break;
case 2:
rule();
break;
case 3:
exit();
break;
default:
cout<<"Error, bad input" << endl;
break;
}
}
void game(void){
string player[2];
int player_pick[2]={0,0};
bool y;
int temp_choice =0;
int e=0;
cout<<"Please enter player one name : " << endl;
cin >> player[0];
cout<<"please enter player two name : " << endl;
cin >> player[1];
for (int i=0; i < 2; i++) {
y = false;
while (y != true){
cout << player <<" Scissors [1] :: Paper [2] :: Rock [3]" << endl;
cin >> temp_choice;
if (temp_choice == 1 || temp_choice == 2 || temp_choice == 3){
y = true;
player_pick = temp_choice;
}
else {
cout << "Wrong Input \n";
}
}
}
if ( player_pick[0] == 1 || player_pick[1] == 1,player_pick[0] == 2 || player_pick[1] == 2,player_pick[0] == 3 || player_pick[1] == 3 ){
cout << player[0] << " and "<< player[1]<< " tied " << endl;
}
if ( player_pick[0] == 1 || player_pick[1] == 2,player_pick[0] == 2 || player_pick[1] == 3,player_pick[0] == 3 || player_pick[1] == 1 ){
cout << player[0] << " wins the game " << endl;
}
if ( player_pick[1] == 1 || player_pick[0] == 2,player_pick[1] == 2 || player_pick[0] == 3,player_pick[1] == 3 || player_pick[0] == 1 ){
cout << player[1] << " wins the game " << endl;
}
cout << "##############" << endl << endl << endl;
menu();
}
void rule(void){
// place to see the rule :!
menu();
}
void exit(void){
// end program
cout << "Developed by : CrazyElmo" << endl;
}
haven't done C++ in a very long time... Mainly do C# or PHP or ASP !!
The program can be segmented into smaller
Anyways... spend some time making it look good
#include <iostream>
#include <string>
using namespace std;
// Function Prototype
void menu(void);
void game(void);
void rule(void);
void exit(void);
int main() {
menu();
return 0;
}
void menu(void) {
int input;
cout << "########################################################" << endl;
cout << "##############---Rock-Paper-Scissors---#################" << endl;
cout << "########################################################" << endl;
cout << "MENU :" << endl;
cout << "1. Play Rock-Paper-Scissors" << endl;
cout << "2. Game Rule" << endl;
cout << "3. Exit " << endl;
cout << "" << endl;
cout <<"Selection: ";
cin >> input;
switch ( input ) {
case 1:
game();
break;
case 2:
rule();
break;
case 3:
exit();
break;
default:
cout<<"Error, bad input" << endl;
break;
}
}
void game(void){
string player[2];
int player_pick[2]={0,0};
bool y;
int temp_choice =0;
int e=0;
cout<<"Please enter player one name : " << endl;
cin >> player[0];
cout<<"please enter player two name : " << endl;
cin >> player[1];
for (int i=0; i < 2; i++) {
y = false;
while (y != true){
cout << player <<" Scissors [1] :: Paper [2] :: Rock [3]" << endl;
cin >> temp_choice;
if (temp_choice == 1 || temp_choice == 2 || temp_choice == 3){
y = true;
player_pick = temp_choice;
}
else {
cout << "Wrong Input \n";
}
}
}
if ( player_pick[0] == 1 || player_pick[1] == 1,player_pick[0] == 2 || player_pick[1] == 2,player_pick[0] == 3 || player_pick[1] == 3 ){
cout << player[0] << " and "<< player[1]<< " tied " << endl;
}
if ( player_pick[0] == 1 || player_pick[1] == 2,player_pick[0] == 2 || player_pick[1] == 3,player_pick[0] == 3 || player_pick[1] == 1 ){
cout << player[0] << " wins the game " << endl;
}
if ( player_pick[1] == 1 || player_pick[0] == 2,player_pick[1] == 2 || player_pick[0] == 3,player_pick[1] == 3 || player_pick[0] == 1 ){
cout << player[1] << " wins the game " << endl;
}
cout << "##############" << endl << endl << endl;
menu();
}
void rule(void){
// place to see the rule :!
menu();
}
void exit(void){
// end program
cout << "Developed by : CrazyElmo" << endl;
}
haven't done C++ in a very long time... Mainly do C# or PHP or ASP !!
The program can be segmented into smaller
