Below is my code. I have made this program and now am trying to use functions in it and I CAN'T use global variables. Can I get some pointers on what to do? Am I using my functions correctly? I am new to this...
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace std;
void myFunction(double randomizer, double selection)
{
for(int i=1; i<=12; i++) //12 iterations starting from 1
{
randomizer = rand() % 2;
if (randomizer == 0)
{
selection += ( selection == 8 ) ? -0.5 : 0.5;
}
else
{
selection += ( selection == 0 ) ? 0.5 : -0.5;
}
cout << selection << endl; //print out the 12 iterations
}
}
int myOtherFunction(int selection, int user_winnings)
{
if (selection == 0){
user_winnings = 100;
}
if (selection == 1){
user_winnings = 500;
}
if (selection == 2){
user_winnings = 1000;
}
if (selection == 3){
user_winnings = 0;
}
if (selection == 4){
user_winnings = 10000;
}
if (selection == 5){
user_winnings = 0;
}
if (selection == 6){
user_winnings = 1000;
}
if (selection == 7){
user_winnings = 500;
}
if (selection == 8){
user_winnings = 100;
return user_winnings;
}
}
int main()
{
//set variables
int choice;
double selection;
int where_drop = 0;
double user_winnings;
int randomizer;
int multiple_chips;
double selection_two;
int randomizer_two;
double user_winnings_two;
double average_winnings;
bool gameOn = true;
//make menu screen
while (gameOn != false){
cout << "***GAME MENU***\n";
cout << " 1 - Drop one chip into one slot.\n";
cout << " 2 - Drop multiple chips into one slot.\n";
cout << " 3 - Drop Multiple chips into every slot.\n";
cout << " 4 - Exit.\n";
cin >> choice;
//menu choices below in switch
switch (choice)
{
case 1:
cout << "\n Which Slot would you like to Drop a chip in(Please enter a slot #0-8)?"<<"\n";
cin >> selection;
if((selection < 0) || (selection > 8))//if a negative number or greater than 8 go back to menu
{
break;
}
srand(time(0)); //seed the random number
void myFunction();
//find winnings
int myOtherFunction();
//print out winnings
cout<<"You've won $" << user_winnings << "!" << endl;
break;
case 2: //second option
cout << "\n How many chips would you like to play?"<<"\n";
cin >> multiple_chips;
if(multiple_chips < 0)//don't allow negative numbers
{
break;
}
cout << "\n Which Slots would you like to Drop the chip(s) into(Please enter a slot #0-8)?"<<"\n";
cin >> selection;
if((selection < 0) || (selection > 8))//only allow 0-8 as option or return to menu
{
break;
}
void myFunction();
//find winnings.
int myOtherFunction();
//final calculations
average_winnings = user_winnings / multiple_chips;
cout<<"You've won a total of $" << user_winnings << "!" << endl;
cout<<"You averaged winnings of $" << average_winnings << " a chip." << endl;
break;
case 3:
cout << "New stuff.\n";//working on finishing
break;
case 4://quit program
cout << "End of Program.\n";
gameOn = false;
break;
default:
cout << "Not a Valid Choice. \n";
cout << "Choose again.\n";
break;
cin >> choice;
}
}
return 0;
}