Skip to content
← Back to Community
I need help
Profile icon
Emel1235JR

I made this program its like a gamble game:
You tell the program how many times you want to toss a coin for example 5 times, so you toss a coin 5 times and then you bet on heads/tails and if you choose idk heads and you have more heads than tails you win and you can choose to continou or end but if you choose tails and have more heads than tails you lose, and you have points every head/tail is 1 point.
But it doesn`t work.
(Keep in mind its not finished i just wanted to make it work first and then to add more).
Can someone help plz.

#include
#include
#include
using namespace std;

int coinToss(void){

int randomNumber;
randomNumber = 1 + rand() % 2;
return randomNumber;
}

int main() {

int howManyTimes = 0;
int randomNumebr = 0;
int headPoints = 0;
int tailPoints = 0;
int bet = 0;
int ContinouEnd;
string headTail = "";

cout <<"How many times to toss the coin? " ;
cin >> howManyTimes;

cout << "Do you bet on heads or tails? " << endl ;
cin >> bet;

srand((time(0)));//seeding the random number generator.

for(int i = 1; i <= howManyTimes; i++){
randomNumebr = coinToss();
if(randomNumebr == 1){
headTail = "head" ;

headPoints++; } else headTail = "tail"; tailPoints++; cout << headTail << endl ;

}
if(headPoints > tailPoints ){
if(bet == 1){
cout << headPoints << endl ;
cout << "Continou, or end? " << endl ;

cin >>ContinouEnd ; if(ContinouEnd == 1){ cout << "Ok, we are continouing. " << endl ; } else if(ContinouEnd == 2){ cout << "Ok, great job your score is: " << tailPoints << endl ; return 0;

}
}
}
if (tailPoints > headPoints ){
if(bet == 2){
cout << tailPoints << endl ;
cout << "Continou, or end?" << endl ;
cin >> ContinouEnd ;

if(ContinouEnd == 1){ cout << "Ok, we are continouing. " << endl ; } else if(ContinouEnd == 2){ cout << "Ok, great job your score is: " << tailPoints << endl ; return 0; } }

}
else{
cout << "You lost " << endl ;
return 0;
}

return 0;
}

Voters
Profile icon
Emel1235JR
Comments
hotnewtop
Profile icon
Gekot

There are many online casino games that can be played on mobile through their website or apps. There are also many sites worth mentioning, such as https://ozwin.casinologin.click .
I mentioned this site because it is trustworthy and safe to play. Plus, it has a lot of welcome bonuses and a few casino games. I have been playing on this site for a long time and I think you should visit it too.

Profile icon
JBloves27

Umm, try attaching the repl?

Profile icon
RYANTADIPARTHI

What is your problem. What do you want us to solve?

Profile icon
Coder100

what part doesn't work? Attach your repl actually please

Profile icon
Emel1235JR
Profile icon
Coder100

ok.The problem is that you are using std::cin, so if the user gives some invalid code, its going to skip everything else.

Use getline instead:

string inp; getline(cin, inp); if (inp == "...") ...

@Emel1235JR