While loop not working...

I am in the process of creating a game that has two players machine and person. The player is selected randomly each round. So if the player is selected, he needs to choose a number from 1-9. Then the machine needs to choose another distincit new number either in the same row or colunm. Then keep going until someone reaches 31.

I´m stuck on how to add the numbers from previous rounds and have them reflect in the new rounds. While at the same time using the last entered number(last number) as a reference has to whether or not the new number is valid.

I created a while loop. But it is not adding each round like it should. So the question is: What is wrong with the code after the while loop?

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
38
39
40
41
42
43
44
45
46
47
48
49
50
 

	while ((x != 0) && (suma < Meta)){
		
		
		
		
		cout << "SUM =" << x + last number << endl;
		
		
		
		if (player == Person) {
		
		x = machinerandomnDigit(last number);
		sum = sum + x;
		player = Person;
		last number = x;





		}

		else {

			x = machinerandomDigit(ultimo);
			sum = sum + x;
			player = Person;
			last number = x;
		}



	}
	
	
	
	

		cin.sync();
		cin.get();
		system("pause");
		return whoStarts();


		
		
	
Last edited on
Your while loop should start somewhere. You're just saying while x not 0 and suma less then Meta but don't tell the loop where to start. Besides You're setting x to 1 so x is always gonna be not zero. And the argument last number to all your functions is not valid.

You should start by something simple first and not with 192 lines of code and 30-40 mistakes.
Last edited on
Thanks for your reply, then my next step should be to put and if statement after my while statement, correct?

And I set x to 1 because when I set x to 0, the loop would never start...
Topic archived. No new replies allowed.