Friends i just wanna rewrite this program using File in c++
#include<iostream>
#include<stdlib.h>
using namespace std;
struct game
{
char name[23];
int guse;
float bets;
int coupon;
int i;
float coin;
};
void name(game*);
void bets(game*);
void coin(game*);
void guseno(game*);
void coupon(game*);
void tossed(game*);
void output(game*);
int main()
{
game g;
char ch;
name(&g);
bets(&g);
coupon(&g);
do
{
coin(&g);
tossed(&g);
guseno(&g);
output(&g);
cout<<"do you want to play again (Y/N)\n";
cin>>ch;
}while((ch=='y'||ch=='Y'));//ppress y toplay again&pres n to stop game
cout<<" Thanks for coming ";
return 0;
}
void name(game *a)
{
cout<<"enter the players name\n";
cin>>a->name;//player name
}
void bets(game*b)
{
cout<<"enter the bets\n";
cin>>b->bets;
}
void coupon(game*f)
{
cout<<"enter the coupon number\n";
cin>>f->coupon;
}
void coin(game*c)
{
cout<<"enter the coin that you play\n";
cin>>c->coin;
}
void tossed(game*z)
{
z->i=rand()%5+1;//random no genratore
}
void guseno(game*w)
{
cout<<"enter your guse \n";
cin>>w->guse;
}
void output(game *y)
{
cout<<"hey "<<y->name<<" ,"<<"hope you enjoyed the game\n";
cout<<"===============================================\n";
cout<<" coupon number 000000"<<y->coupon<<endl;
cout<<"congratulations!!!! you have collected "<<y->bets<<"Birr"<<endl;
cout<<"please take your money from the counter"<<endl;
cout<<"=======================================================\n";
use a class instead of a struct, all of your data members should be private, the methods you've declared under your struct might then become public methods.
You'll need accessors and possibly setters for your private stuff.
have a read here: http://www.cplusplus.com/doc/tutorial/classes/
you should also change this:
char name[23];
to this maybe:
std::string name; // (remember to #include<string>