Pass the calculator!

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?

Before worrying about what to do at line 35, you need to get rid of your compile errors.

line 5: missing keyword enum.

line 20: You have a variable name here which is the same as your enum. Confusing.

Line 24: You can't mix cin and cout in the same statement.

line 26-27: You have a variable names here which are the same as your function names. Poor style. Confusing to the reader.

Line 35: You want to generate a random number between 1 and 2.
1
2
3
4
5
tPlayer whoStarts()
{  int who;
    who = (rnd()%2 )+ 1;
    return (tPlayer)who;
}
Last edited on
Topic archived. No new replies allowed.