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?
// Program reads in two integers
// computes outcome and prints a messsage
// accesses function continue if necessary
#include <iostream>
#include <cmath>
usingnamespace 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;}
elseif ((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){
}
}
}
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.