c++ - How avoid use global variable in simple Slot Machine program -


this simple slot machine program , won know how not use global variable? if helps me clarify subject, because task book offered use function, try not use global variable in particular case.

my code:

int wheel1, wheel2, wheel3;  bool triple_equals(){      if ((wheel1 == wheel2) && (wheel2 == wheel3)){         cout << "jack pot!!! "; cout << "you win!!! ";     }else{         cout << "you loose moneys!!!\n";     } }  int main(){      cout << "wheel 1: \n";     cin >> wheel1;     cout << "wheel 2: \n";     cin >> wheel2;     cout << "wheel 3: \n";     cin >> wheel3;      srand(time(0));     wheel1 = rand() % 2 + 1;     wheel2 = rand() % 2 + 1;     wheel3 = rand() % 2 + 1;      cout << "result wheel 1: " << wheel1 << "\n";     cout << "result wheel 2: " << wheel2 << "\n";     cout << "result wheel 3: " << wheel3 << "\n\n";      triple_equals();      return 0;  } 

use function arguments:

bool triple_equals(const int wheel1,const int wheel2,const int wheel3){      if ((wheel1 == wheel2) && (wheel2 == wheel3)){         cout << "jack pot!!! "; cout << "you win!!! ";     }else{         cout << "you loose moneys!!!\n";     } }  int main(){     int wheel1, wheel2, wheel3;     cout << "wheel 1: \n";     cin >> wheel1;     cout << "wheel 2: \n";     cin >> wheel2;     cout << "wheel 3: \n";     cin >> wheel3;      srand(time(0));     wheel1 = rand() % 2 + 1;     wheel2 = rand() % 2 + 1;     wheel3 = rand() % 2 + 1;      cout << "result wheel 1: " << wheel1 << "\n";     cout << "result wheel 2: " << wheel2 << "\n";     cout << "result wheel 3: " << wheel3 << "\n\n";      triple_equals(wheel1,wheel2,wheel3);      return 0; } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -