need help with using rng and returning strings from functions

every time i run this code it skips to the part where it prompts the user if they would like to go again i don't know why it skips the function call and it doesn't give any errors when compiling greatly appreciate any help given

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
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
int main (){
srand(time(NULL));
string PLAY_AGAIN = "yes";
string RNG_GUESS();
do{
string USER_VS_COMPUTER (string RNG_GUESS()); // the problem appears to be here 
cout << "you would like to play ultimate coin toss simulator.(again?)"; // this prompt and the next cin are looped without running the two functions

cin >> PLAY_AGAIN;
    }
while (PLAY_AGAIN == "yes");
}

string RNG_GUESS (){
int RNG_NUMBER = (rand() % 100) * 100;
if (RNG_NUMBER < 50){
    return "heads";
    }
else if (RNG_NUMBER > 50){
    return "tails";
    }
    else {
        return "your rng number is too high or too low fix it"; // error to test if my rng gave the correct range of outputs
    };
}
string USER_VS_COMPUTER (string RNG_GUESS()){
string USER_INPUT = "q";
cout << "please guess either t (tails) or h (heads).";
cin >> USER_INPUT;
if (USER_INPUT == "h" &&  RNG_GUESS() == "heads"){
cout << "you win";
    }
else if(USER_INPUT == "t" && RNG_GUESS() == "tails"){
    cout << "you win";
    }
else {
    cout << "you lose sorry";
    }
};
string USER_VS_COMPUTER (string RNG_GUESS());
Declare USER_VS_COMPUTER as function
Taking a single parameter named RNG_GUESS
    which is a function
    witout parameters
    returning string
Returng string

This is no a function call, but function declaration.
ok thanks
ok i got the program to work perfectly by making these modifications but the problem is now every time I run it it crashes immediately after it works

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
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
int main (){
 string COMP_CHOICE();
 srand(time(NULL));
 COMP_CHOICE();
 string COMPARISON_(string COMP_CHOICE());
 COMPARISON_(COMP_CHOICE);
 return 0;
}
string COMP_CHOICE () {
int determinate__ = 1;
determinate__ = rand() % 100;
if (determinate__ < 50) {
    return "heads";
    }
    else {
        return "tails";
    }
}
string COMPARISON_(string COMP_CHOICE()){
    string users_choice = "heads";
    cout << "guess which side the coin will land on (heads) or (tails)";
    cin >> users_choice;
    if (users_choice == "heads" && COMP_CHOICE() == "heads"){
        cout << "you win";
    }
    else if (users_choice == "tails" && COMP_CHOICE() == "tails" ){
        cout << "you win";
    }
    else {
        cout << "you lose";
    }
}
string COMPARISON_(string COMP_CHOICE()){
HEre you had promised that you will return a string from this function.
But you never return anything. You broke your promise. So now you have a crash. make your function a void function.
great this worked thanks a ton for the help
Topic archived. No new replies allowed.