No errors, but no output, why?

I have this code that runs smoothly ( no errors) but there is no output. Every time I run it. It says "build succeeded" and that's it. I must be missing something but I can't seem to figure it out and it's driving me nuts. Can anyone help?
Last edited on
I have this code that runs smoothly ( no errors) but there is no output. Every time I run it. It says "build succeeded" and that's it. I must be missing something but I can't seem to figure it out and it's driving me nuts. Can anyone 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

//------------------includes and namespace ---------------------
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <ctime>

using namespace std;

//-----------------class prototype -----------------------------
class TripleString
{
private:
   string string1, string2, string3;
public:
   // static constants
   static const int MAX_STR_LEN = 20;

   //default constructor
   TripleString();

   //mutators and accessors
   bool validString (string str);
   void set (string str1, string str2, string str3);
   string get(int strPosition);
};

//---------------Global scope method prototypes---------------------
int getBet();
TripleString pull();
string randString();
int getPayMultiplier (TripleString thePull);
void display (TripleString thePull, int winnings);

//---------------Main Method ------------------------------------------
int main()
{
   TripleString thePull;
   int bet, mult, winnings;

   while ((bet = getBet()) > 0)
   {  thePull=pull();
      mult = getPayMultiplier(thePull);
      winnings=mult*bet;
      display(thePull,  winnings);
   }
}
//---------------Global Scope Method ----------------------------------
int getBet()
{
   int bet=0;
   int chips=100;

   while ((bet < 0) || (bet > chips))
   {
      cout<< "Enter your bet: ";
      cin>> bet;
   }
   return bet;
}

TripleString pull()
{
   TripleString pullResult;
   cout<<"Whirrrrrrr.... and your pull is ... "<<endl;
   pullResult.set(randString(),randString(),randString());
   return pullResult;
}

string randString()
{
   int prob1 = rand() % 200+1; //generates probability values 0-199
   if (prob1 <100) //50% probability for BAR
      return "BAR";
   else if (prob1 < 150) //25% probability for Cherries
      return "Cherries";
   else if (prob1 <175)  // 12.5% probability for Space
      return "space";
   else // 12.5% probability for 7
      return "7";
}
int getPayMultiplier (TripleString thePull)
{
   if(thePull.get(1)=="cherries" && thePull.get(2)!="cherries")
      return 5;
   else if(thePull.get(1)=="cherries" && thePull.get(2)=="cherries"
           && thePull.get(3)!="cherries")
      return 15;
   else if(thePull.get(1)=="cherries" && thePull.get(2)=="cherries"
           && thePull.get(3)=="cherries")
      return 30;
   else if(thePull.get(1)=="BAR" && thePull.get(2)=="BAR"
           && thePull.get(3)=="BAR")
      return 50;
   else if(thePull.get(1)=="7" && thePull.get(2)=="7" && thePull.get(3)=="7")
      return 100;
   else
      return 0;
}

void display (TripleString thePull, int winnings )
{
   //winnings = mult*bet;
   cout<<thePull.get(1)<<"   "<<thePull.get(2)<<"   "<<thePull.get(3)<<endl;
   if( winnings != 0)
      cout<<"Congratulations!  You won "<<winnings<<"!"<<endl;
   else
      cout<<"Sorry, you lose..."<<endl;
}

// --------------TripleString member functions definitions ------------
// default constructor
TripleString::TripleString()
{
   string1="";
   string2="";
   string3="";
}

// mutators "set" methods
bool TripleString::validString(string str)
{
   if (str.length() <= MAX_STR_LEN)
      return true;

   return false;
}

void TripleString::set(string str1, string str2, string str3)
{
   if (validString(str1))
      string1= str1;
   if (validString(str2))
      string2= str2;
   if (validString(str3))
      string3= str3;
}
// accessor "get" methods
string TripleString::get(int strPosition)
{
   if (strPosition ==1)
      return string1;
   else if (strPosition ==2)
      return string2;
   else
      return string3;
}

The condition on line 54 is false from the start so the loop will never run and the function returns 0. This in turn makes the condition on line 41 false so that loop will also not run.
Last edited on
thanks @Peter87 I fixed the issue and it works great
What happened to the code?
Topic archived. No new replies allowed.