This is my first c++ game and I'm trying to make a balloon popping game where you have a total of 10 balloons and 2 players take turns to pick either 1 or 2 balloons to pop, until there are no balloons left.
I'm stuck trying to get it to keep looping for the next player to have their turn and so on till game over and the last player to pop a balloon wins.
Here's the code I have:
Code:// myballoongame.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <string> #include <ctime> #include <cstdlib> using namespace std; int main() { int rem_balloons = 10; int pick=1, win=0, pturn; srand(time(NULL)); int random = rand(); char player1[20], player2[20]; while (rem_balloons>0) { rem_balloons = 10; win = 0; cout << "Player 1 enter your name: " << endl; cin >> player1; cout << "Player 2 enter your name" << endl; cin >> player2; if (random % 2 == 0) { cout << player1 << " goes first" << endl << endl; pturn = 0; } else { cout << player2 << " goes first" << endl << endl; pturn = 1; } if (rem_balloons >= 0) { cout << "Pick one or two balloons to pop: " << endl; } while (pick != 0) { cin >> pick; if (pick == 1 || pick == 2) { rem_balloons = rem_balloons - pick; pick = 0; cout << "There are " << rem_balloons << " balloons left" << endl; } else { cout << "You must only pick upto 2 balloons to pop" << endl; cout << "Pick again" << endl; cin >> pick; if (!cin) { cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); pick = 3; } if (pick == 1 || pick == 2) { rem_balloons = rem_balloons - pick; pick = 0; cout << "There are " << rem_balloons << " balloons left" << endl; } } } return 0; } }