#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
usingnamespace std;
int ending()
{
int pin2;
cin >> pin2;
if (pin2 == 1)
{
guessing();
}
return 0;
}
int guessing()
{
cout << "Guess one number between 1 and 3\n";
int guess;
guess = rand() % 3+1;
int pin;
cin >> pin;
if (pin == guess)
{
cout << "You did it!\n"
<< "Type <1> if you want to play again\n";
ending();
}
elseif (pin != guess)
{
cout << "You FAIL!\n"
<< "Type >1< if you want to play again\n";
ending();
}
return 0;
}
int main()
{
srand((unsignedint)time(0));
cout << "This is the guess a number game!\n";
guessing();
return 0;
}
I want the "guessing()" to go to "ending()", but since it is before the guessing part, it can't go there. I tried putting "guessing()" after "ending()", but that wouldn't work also.
Anybody know a functioning solution?
Since both functions need to use each other, you can't achieve this by just rearranging them, you can however declare a function without giving the full definition
1 2 3 4 5 6 7 8 9 10 11
int guessing(); // declare the function
int ending() // now ending knows about guessing
{
//....
}
int guessing() // and of course guessing knows about ending as the full definition is above
{
//....
}