Hey guys, im new here and i just created a Roulette program today, and i was trying to figure out how to make a save feature for it..i have an idea of how to do it, but that would only work on my personal computer..
the way i was thinking was to ask the user if they want to save, and if they do 'yes', i would send the amount of money they have to an output file, and the output would just have 1 number in it (their money), and when they want to load, the program would read that number and then insert it into the program, and they can continue from to play with the amount of money they loaded
the only problem is that i would send the output file to a directory on my computer, and if other people played it on their computer, they wouldnt have the same directory as me, so is there any way for the program to create a folder in the users documents called "Roulette" when they open the program ,and have all of the output files go into that folder? thanks for your help, Dan
code for my program is right here incase you wanted to see it:
Code:
#include <iostream>
#include <iomanip>
#include <ctime>
#include <stdlib.h>
#include <conio.h>
using namespace std;
int PickNum();
int SpinWheel(int choice);
int StraightBet();
int RedBet();
int BlackBet();
int EvenBet();
int OddBet();
int First12();
int Second12();
int Third12();
//gobal variables
int bank=100;
int amountBet;
const SIZE=100;
//end global variables
int main ()
{
srand(unsigned(time(0)));
do
{
int choice=PickNum();
SpinWheel(choice);
}
while(bank!=0);
system("cls");
if(bank==0)
cout<<"\n\n\n\t\tYou lose, you don't have any more money!\n\n\n\n\n";
return 0;
}
int PickNum()
{
system("cls");
int choice;
cout<<"\n\n\t\tWhat do you want to bet on?\n";
cout<<"\n\tStraight bet(#00-36)...1"<<endl;
cout<<"\tRed....................2"<<endl;
cout<<"\tBlack..................3"<<endl;
cout<<"\tEven...................4"<<endl;
cout<<"\tOdd....................5"<<"\t\tBank: $"<<bank<<"\n";
cout<<"\tFirst 12...............6"<<endl;
cout<<"\tSecond 12..............7"<<endl;
cout<<"\tThird 12...............8"<<endl;
cout<<"\n\tChoose an option: ";
cin>>choice;
cout<<"\n\n Amount to bet from bank: ";
cin>>amountBet;
if(amountBet>bank)
{
cout<<"\n\tYou bet more than the bank! Press any key and try again.";
getch();
PickNum();
}
return choice;
}
int SpinWheel(int choice)
{
if(choice==1)
StraightBet();
if(choice==2)
RedBet();
if(choice==3)
BlackBet();
if(choice==4)
EvenBet();
if(choice==5)
OddBet();
if(choice==6)
First12();
if(choice==7)
Second12();
if(choice==8)
Third12();
return 0;
}
int StraightBet()
{
system("cls");
int WinningNum=rand()%38+1;
//cout<<WinningNum;
int StraightBetChoice;
cout<<"\n\n\tChoose a number from 0-36, or 00: ";
cin>>StraightBetChoice;
if(StraightBetChoice==WinningNum)
{
cout<<"Winner!";
bank=bank+amountBet*25;
cout<<"\tYou now have $"<<bank;
getch();
}
if(StraightBetChoice!=WinningNum)
{
cout<<"\n\tLoser! The winning number was "<<WinningNum<<".\n\n";
bank=bank-amountBet;
cout<<"\tYou now have $"<<bank;
getch();
}
return 0;
}
int RedBet()
{
system("cls");
//1 is red and 2 is black
int WinningNum=rand()%2+1;
if(WinningNum==1)
{
cout<<"\n\n\n\n\tThe number rolled was red, you are a winner!";
bank=bank+(amountBet*2);
cout<<"\n\n\t\tYou now have $"<<bank;
getch();
}
if(WinningNum==2)
{
cout<<"\n\n\n\n\tYou lose, the number rolled was black!";
bank=bank-amountBet;
cout<<"\n\n\t\tYou now have $"<<bank;
getch();
}
return 0;
}
int BlackBet()
{
system("cls");
//1 is red and 2 is black
int WinningNum=rand()%2+1;
if(WinningNum==2)
{
cout<<"\n\n\n\n\tThe number rolled was black, you are a winner!";
bank=bank+(amountBet*2);
cout<<"\n\n\t\tYou now have $"<<bank;
getch();
}
if(WinningNum==1)
{
cout<<"\n\n\n\n\tYou lose, the number rolled was red!";
bank=bank-amountBet;
cout<<"\n\n\t\tYou now have $"<<bank;
getch();
}
return 0;
}
int EvenBet()
{
system("cls");
int WinningNum=rand()%38+1;
if(WinningNum%2==0)
{
cout<<"\n\n\n\n\tThe number rolled was even ("<<WinningNum<<"), you are a winner!";
bank=bank+(amountBet*2);
cout<<"\n\n\t\tYou now have $"<<bank;
getch();
}
if(WinningNum%2!=0)
{
cout<<"\n\n\n\n\tYou lose, the number rolled was odd! ("<<WinningNum<<").";
bank=bank-amountBet;
cout<<"\n\n\t\tYou now have $"<<bank;
getch();
}
return 0;
}
int OddBet()
{
system("cls");
int WinningNum=rand()%38+1;
if(WinningNum%2!=0)
{
cout<<"\n\n\n\n\tThe number rolled was odd ("<<WinningNum<<"), you are a winner!";
bank=bank+(amountBet*2);
cout<<"\n\n\t\tYou now have $"<<bank;
getch();
}
if(WinningNum%2==0)
{
cout<<"\n\n\n\n\tYou lose, the number rolled was even! ("<<WinningNum<<").";
bank=bank-amountBet;
cout<<"\n\n\t\tYou now have $"<<bank;
getch();
}
return 0;
}
int First12()
{
system("cls");
int WinningNum=rand()%38+1;
if(WinningNum<=12)
{
cout<<"\n\n\n\n\tThe number rolled was in the first 12 ("<<WinningNum<<"), you are a winner!";
bank=bank+(amountBet*3);
cout<<"\n\n\t\tYou now have $"<<bank;
getch();
}
if(WinningNum>12)
{
cout<<"\n\n\n\n\tThe number rolled was NOT in the first 12 ("<<WinningNum<<"), you lose!";
bank=bank-amountBet;
cout<<"\n\n\t\tYou now have $"<<bank;
getch();
}
return 0;
}
int Second12()
{
system("cls");
int WinningNum=rand()%38+1;
if(WinningNum>=13&&WinningNum<=24)
{
cout<<"\n\n\n\n\tThe number rolled was in the second 12 ("<<WinningNum<<"), you are a winner!";
bank=bank+(amountBet*3);
cout<<"\n\n\t\tYou now have $"<<bank;
getch();
}
if(WinningNum<13||WinningNum>24)
{
cout<<"\n\n\n\n\tThe number rolled was NOT in the second 12 ("<<WinningNum<<"), you lose!";
bank=bank-amountBet;
cout<<"\n\n\t\tYou now have $"<<bank;
getch();
}
return 0;
}
int Third12()
{
system("cls");
int WinningNum=rand()%38+1;
if(WinningNum>24)
{
cout<<"\n\n\n\n\tThe number rolled was in the third 12 ("<<WinningNum<<"), you are a winner!";
bank=bank+(amountBet*3);
cout<<"\n\n\t\tYou now have $"<<bank;
getch();
}
if(WinningNum<=24)
{
cout<<"\n\n\n\n\tThe number rolled was NOT in the third 12 ("<<WinningNum<<"), you lose!";
bank=bank-amountBet;
cout<<"\n\n\t\tYou now have $"<<bank;
getch();
}
return 0;
}