Hiya,
I'm new to C++, and working on Windows 7 with Visual Studio Express 2012. I've pasted my code below. The winnings variable that is declared and defined in the main generates an error within the method that calls it ( the void display method at the bottom ). Any pointers? I hit a wall with this two days ago and have been ineffectually flailing around since. Thanks in advance.
Here are the errors that are generated:
Warning 1 warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data c:\users\dev\do cuments\visual studio 2012\projects\c onsoleapplicati on6\consoleappl ication6\consol eapplication6.c pp 88 1 ConsoleApplicat ion6
Error 2 error C2065: 'winnings' : undeclared identifier c:\users\dev\do cuments\visual studio 2012\projects\c onsoleapplicati on6\consoleappl ication6\consol eapplication6.c pp 199 1 ConsoleApplicat ion6
Error 3 error C2065: 'winnings' : undeclared identifier c:\users\dev\do cuments\visual studio 2012\projects\c onsoleapplicati on6\consoleappl ication6\consol eapplication6.c pp 201 1 ConsoleApplicat ion6
4 IntelliSense: identifier "winnings" is undefined c:\Users\dev\Do cuments\Visual Studio 2012\Projects\C onsoleApplicati on6\ConsoleAppl ication6\Consol eApplication6.c pp 199 7 ConsoleApplicat ion6
I'm new to C++, and working on Windows 7 with Visual Studio Express 2012. I've pasted my code below. The winnings variable that is declared and defined in the main generates an error within the method that calls it ( the void display method at the bottom ). Any pointers? I hit a wall with this two days ago and have been ineffectually flailing around since. Thanks in advance.
Code:
#include <ctime>
#include <iostream>
#include <sstream>
#include <string.h>
#include <random>
using namespace std;
class TripleString
{
string string1, string2, string3;
public:
static const int MAX_LEN=20;
TripleString();
bool validString( string str );
void set(string str1, string str2, string str3);
string get(int strPosition);
};
TripleString::TripleString()
{
string1="";
string2="";
string3="";
}
bool TripleString::validString(string str)
{
if (str.length()<=MAX_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;
}
}
string TripleString::get(int pos)
{
if(pos==1)
{
return string1;
}
if(pos==2)
{
return string2;
}
if(pos==3)
{
return string3;
}
}
int getBet();
TripleString pull();
string randString();
int getPayMultiplier (TripleString thePull);
void display (TripleString thePull, int winnings );
int main()
{
srand( time( NULL ) );//seed for rand method
TripleString thePull;
int bet, mult, winnings;
//string mult, bet;
bet = getBet();
//stringstream convert(bet);
//if ( !(convert >> int_bet) )
if(bet==0)
return 0;
thePull=pull();
mult = getPayMultiplier(thePull);
//stringstream convert(mult);
//if ( !(convert >> int_mult) )
winnings=mult*bet;
display(thePull, winnings);
}
int getBet()
{
int betAmount;
cout<<"enter bet amount (1-100), entering a zero will terminate the program: ";
cin>>betAmount;
if(betAmount==0)
{
return 0;
}
else if(betAmount>=1 && betAmount<=100)
{
return betAmount;
}
do
{
cout<<"invalid bet. please bet between 1 and 100: ";
cin>>betAmount;
}
while(betAmount>100||betAmount<0);
}
TripleString pull()
{
TripleString pullResult;
cout<<"Whirrrrrrrr....and your pull is...."<<endl;
pullResult.set(randString(),randString(),randString());
return pullResult;
}
string randString()
{
int randNum;
randNum=rand()%100+1;
if(randNum<=50)//20000*50=10000
return "BAR";
else if(randNum>50 && randNum<=75)//20000*25=5000
return "cherries";
else if(randNum>75 && randNum <=87)//20000*12.5=2500
return "space";
else if(randNum>87 && randNum <=100)//20000*12.5=2500
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;
}
}
}
Warning 1 warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data c:\users\dev\do cuments\visual studio 2012\projects\c onsoleapplicati on6\consoleappl ication6\consol eapplication6.c pp 88 1 ConsoleApplicat ion6
Error 2 error C2065: 'winnings' : undeclared identifier c:\users\dev\do cuments\visual studio 2012\projects\c onsoleapplicati on6\consoleappl ication6\consol eapplication6.c pp 199 1 ConsoleApplicat ion6
Error 3 error C2065: 'winnings' : undeclared identifier c:\users\dev\do cuments\visual studio 2012\projects\c onsoleapplicati on6\consoleappl ication6\consol eapplication6.c pp 201 1 ConsoleApplicat ion6
4 IntelliSense: identifier "winnings" is undefined c:\Users\dev\Do cuments\Visual Studio 2012\Projects\C onsoleApplicati on6\ConsoleAppl ication6\Consol eApplication6.c pp 199 7 ConsoleApplicat ion6
Comment