I have to do a game using a calculator and the first step is to choose who starts, the player or the computer, it has to be random and I don't know how to do it.
This is how it should look:
Welcome to Pass the calculator!
What is your name? Ana
Hi, Ana
You start
<--- My problem
7 8 9
4 5 6
1 2 3
Please enter a digit (0 to abandon): 2
SUM = 2
I chose 8
SUM = 10
7 8 9
4 5 6
1 2 3
Please enter a digit (0 to abandon): 2
SUM = 12
I chose 8
SUM = 20
7 8 9
4 5 6
1 2 3
Please enter a digit (0 to abandon): 8
Error: It must be different than 8 and be in the same row or column
7 8 9
4 5 6
1 2 3
Please enter a digit (0 to abandon): 4
Error: It must be different than 8 and be in the same row or column
7 8 9
4 5 6
1 2 3
Please enter a digit (0 to abandon): 9
SUM = 29
I chose 3
SUM = 32
Congratulations! You won!
See you, Ana (press Enter to exit)
I got this code by now:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
#include <string>
using namespace std;
typedef goal{ None, Computer, User } tPlayer;
tPlayer passCalculator();
tPlayer whoStarts();
bool sameRow(int last, int next);
bool sameColumn(int last, int next);
bool validDigit(int last, int next);
int randomNumber();
int computerDigit(int last);
int userInput();
int userDigit(int ultimo);
int main() {
const int goal = 31;
string name;
cout << "Welcome to Pass the Calculator!" << endl;
cout << "What is your name?" << cin name << endl;
cout << "Hi, " << name << endl;
tPlayer whoStarts;
tPlayer passCalculator;
return 0;
}
tPlayer passCalculator() {}
tPlayer whoStarts() {} //<--What should i do here?
|