function to return a integer to print back in main

Hello,

i'm trying to get the function to return a digit 0 for winner 1 for loser and 2 for a draw. so i could print the message

if 5 7 12 it print winner

if 2 4 11 it print loser

anything else is a draw

I appreciate any help

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <cstdlib>
#include <fstream>

using namespace std;

int main()
{
int die1=0;
int die2=0;
//counter for winners
int winner=0;
//counter for losers
int loser=0;
//counter for draw
int draw=0;

//func to determine the outcome
int outcome(int, int);
//func for random numbers
int rollDice();








cout <<"Enter Two Numbers To Play a Game Of Dice\n";
cin >> die1>> die2;
cout <<"You Entered : "<< die1<<" "<<die2<<endl;
while (die1>=1 && die2<=6) {

case 0: cout <<" You A Winner\n"; break;

case 1: cout <<" You A Loser\n"; break;

case 2: cout <<" A Draw\n"; break;


// to get the next two value
cin >> die1>> die2;
cout <<"You Entered : "<< die1<<" "<<die2<<endl;



}



return 0;
}

//function
int outcome(int, int)
{
int die1;
int die2;


if (die1+die2==5 || die1+die2==7 || die1+die2==12)

return 0;

if (die1+die2==2 || die1+die2==4 || die1+die2==11)

return 1;

else
return 2;
}



// func to get a random number
int rollDice()
{
int roll;

roll = (rand()%6)+1;

return roll;
}
Last edited on
some of your syntax is off:
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
#include <iostream>
#include <cstdlib>
#include <fstream>

// Function declarations here
int outcome(int, int);
int rollDice();

// Begin main
int main()
{
  int roll01  = rollDice(); // must declare a variable
  int roll02  = rollDice();
  int result = outcome(roll01, roll02);

  // Do stuff with result
 
  return 0;
}

// Function definitions
int outcome(int, int)
{
  int whatHappned;

  // stuff

  return whatHappend;
}
int rollDice()
{
  return 5; // I picked it randomly :)
} 


Also, please put the code tags around your code (via the <> button to the right of the post box).


Last edited on
thank you :) i see it more clearly now


thank you for informing me about having the source code <>
Last edited on
Topic archived. No new replies allowed.