Dice game problem

in function continue if the value adds up to 7 then you lose, if it adds up to the sum of the previous two number you win, else go again. How to return to main func after i went through the func continue?

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
51
52
53
54
55
56
57
58
59
60
61
62
// Program reads in two integers
// computes outcome and prints a messsage
// accesses function continue if necessary 
#include <iostream>
#include <cmath>
using namespace std;
int outcome(int, int);
void continueF(int);
int main()
       {

      int x, y, z, die1, die2;
      cout<<"Enter two number bettwen 1 and 6, negative to stop"<<endl;
      cout<<"Enter a number: ";
      cin>>die1;
      cout<<"Enter another number: ";
      cin>> die2;
    while (((die1>= 0) && (die2>= 0)) &&                    //game continues while both
	(((die1>=1)&&(die1<=6)) && ((die2>=1)&&(die2<=6))))	{  // values are positive
    z=outcome(die1, die2);                                 // and between 1 and 6
    cout << endl << "Numbers entered were " << die1 << " and " << die2<<endl;
	cout<< "Outcome is " << z<<endl;
	if ((z==7)||(z==11)){
        cout << "You Win!!!"<<endl;}
    else if ((z==2)||(z==12)){
        cout << "You lose!"<<endl;}
    else {continueF(z);}
cout << endl << "Enter two numbers between 1 and 6, negative to stop" << endl;
cout << "Enter number: ";
cin >> die1;
cout << "Enter another number: ";
cin >> die2;
}
      return 0;
      }
      int outcome (int x,int y){
      int sum=0;
      sum=x+y;
      return sum;
      }
      void continueF (int previousValue){
      int number1,number2;
      int sum=0;
      while (sum!=7 || sum!=previousValue){
      cout<<"The game continues "<< endl;
      cout<<"Please enter two more numbers "<< endl;
      cout << "Enter number: ";
	  cin>>number1;
	  cout << "Enter one more number: ";
      cin>>number2;
      sum=number1+number2;
      if (sum==7){
      cout<<"You Lose!";
      }
      if (sum==previousValue){
     cout<<"You Win!";
      }
     if (sum!=7 || sum!=previousValue){

}
}
      }
Last edited on
Shouldn't the die roll be a random number? I can't think of any reason the user would intentionally enter loosing values unless they wanted to lose for some reason.
Topic archived. No new replies allowed.