Having Unknown Troubles

cannot figure out what is wrong with this code:
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
void play(){
	cout<<""<<endl;
	srand ( time(NULL) );
	r = rand() % 6 + 1;
	cout<<"Your total is "<< t <<"!"<<endl;
	cout<<"Pick a deck"<<endl;
	cout<<"Red or Blue"<<endl;
	cin>> x;
	cout<<"Place Your Bet"<<endl;
	cin>> e;
	if (x == "Red" || x == "red"){
		if (r == 1 || r == 2)
			t = t + b;
		if (r == 3 || r == 4 || r == 5 || r == 6)
			t = t - b;
	}
	if (x == "Blue" || x == "blue"){
		if (r == 1 || r == 2 || r == 3)
			t == t + b;
		if (r == 4 || r == 5 || r == 6)
			t == t - b;
	}
	else
		play();
}


if you need the output just ask
Last edited on
I spot 2 things:

1) don't call srand every time you call rand. srand should be called only once at program startup.

2) don't recurse on the function call (ie: play() should not call play() to repeat itself). If you want code to loop, put it in a loop:

1
2
3
4
while( some_condition )
{
  // code in here will repeat as long as 'some_condition' is true
}




Other than that... define "wrong". What makes you think something is wrong with it?
this is what i changed it to. still having problems

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
void play(){
	while{z == 1}
	{
		system("cls");
		cout<<""<<endl;
		r = rand() % 6 + 1;
		cout<<"Your total is "<< t <<"!"<<endl;
		cout<<"Pick a deck"<<endl;
		cout<<"Red or Blue"<<endl;
		cin>> x;
		cout<<"Place Your Bet"<<endl;
		cin>> e;
		if (x == "Red" || x == "red"){
			if (r == 1 || r == 2)
				t = t + b;
			if (r == 3 || r == 4 || r == 5 || r == 6)
				t = t - b;
		}
		if (x == "Blue" || x == "blue"){
			if (r == 1 || r == 2 || r == 3)
				t == t + b;
			if (r == 4 || r == 5 || r == 6)
				t == t - b;
		}
	}
}	
Do not use system ();
http://www.cplusplus.com/forum/beginner/1988/#msg7275
What are your problems?
here part of the output

1>------ Build started: Project: red blue betting version, Configuration: Debug Win32 ------
1>Build started 8/22/2011 7:47:25 PM.
1>InitializeBuildStatus:
1>  Touching "Debug\red blue betting version.unsuccessfulbuild".
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>ClCompile:
1>  main.cpp
1>main.cpp(37): error C2059: syntax error : '{'
1>main.cpp(37): error C2143: syntax error : missing ';' before '{'
1>main.cpp(37): error C2143: syntax error : missing ';' before '}'
1>main.cpp(37): warning C4553: '==' : operator has no effect; did you intend '='?
1>main.cpp(50): error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(std::basic_string<_Elem,_Traits,_Alloc> &&,const _Elem)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &&' from 'int'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(153) : see declaration of 'std::operator +'
1>main.cpp(50): error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(std::basic_string<_Elem,_Traits,_Alloc> &&,const _Elem *)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &&' from 'int'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(143) : see declaration of 'std::operator +'
1>main.cpp(50): error C2782: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const _Elem,std::basic_string<_Elem,_Traits,_Alloc> &&)' : template parameter '_Elem' is ambiguous
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(133) : see declaration of 'std::operator +'
1>          could be 'char'
1>          or       'int'
1>main.cpp(50): error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const _Elem *,std::basic_string<_Elem,_Traits,_Alloc> &&)' : could not deduce template argument for 'const _Elem *' from 'int'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(123) : see declaration of 'std::operator +'
1>main.cpp(50): error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(std::basic_string<_Elem,_Traits,_Alloc> &&,std::basic_string<_Elem,_Traits,_Alloc> &&)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &&' from 'int'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(109) : see declaration of 'std::operator +'
1>main.cpp(50): error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(std::basic_string<_Elem,_Traits,_Alloc> &&,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &&' from 'int'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(99) : see declaration of 'std::operator +'
1>main.cpp(50): error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const std::basic_string<_Elem,_Traits,_Alloc> &,std::basic_string<_Elem,_Traits,_Alloc> &&)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'int'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(89) : see declaration of 'std::operator +'
1>main.cpp(50): error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'int'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(75) : see declaration of 'std::operator +'
1>main.cpp(50): error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'int'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(61) : see declaration of 'std::operator +'
1>main.cpp(50): error C2782: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const _Elem,const std::basic_string<_Elem,_Traits,_Alloc> &)' : template parameter '_Elem' is ambiguous
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(47) : see declaration of 'std::operator +'
1>          could be 'char'
1>          or       'int'
1>main.cpp(50): error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'int'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(33) : see declaration of 'std::operator +'
1>main.cpp(50): error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'int'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(19) : see declaration of 'std::operator +'
1>main.cpp(50): error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_iterator<_Elem,_Traits,_Alloc>' from 'std::string'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xstring(434) : see declaration of 'std::operator +'
1>main.cpp(50): error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_iterator<_Elem,_Traits,_Alloc>' from 'std::string'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xstring(434) : see declaration of 'std::operator +'
1>main.cpp(50): error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_iterator<_Elem,_Traits,_Alloc>' from 'std::string'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xstring(434) : see declaration of 'std::operator +'
1>main.cpp(50): error C2784: 'std::_String_const_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_const_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_const_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' from 'std::string'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xstring(293) : see declaration of 'std::operator +'
1>main.cpp(50): error C2784: 'std::_String_const_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_const_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_const_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' from 'std::string'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xstring(293) : see declaration of 'std::operator +'
1>main.cpp(50): error C2784: 'std::_String_const_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_const_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_const_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' from 'std::string'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xstring(293) : see declaration of 'std::operator +'
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
void play(){
	while{z == 1} // should be while(z==1)
	{
		system("cls");
		cout<<""<<endl;
		r = rand() % 6 + 1;
		cout<<"Your total is "<< t <<"!"<<endl;
		cout<<"Pick a deck"<<endl;
		cout<<"Red or Blue"<<endl;
		cin>> x;
		cout<<"Place Your Bet"<<endl;
		cin>> e;
		if (x == "Red" || x == "red"){
			if (r == 1 || r == 2)
				t = t + b;
			if (r == 3 || r == 4 || r == 5 || r == 6)
				t = t - b;
		}
		if (x == "Blue" || x == "blue"){
			if (r == 1 || r == 2 || r == 3)
				t == t + b; // should be t = t + b;
			if (r == 4 || r == 5 || r == 6)
				t == t - b;// should be t = t - b;
		}
	}
}	
That helped. totally missed that coding error. its still telling me

Error	5	error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(std::basic_string<_Elem,_Traits,_Alloc> &&,const _Elem)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &&' from 'int'	C:\Documents and Settings\Guest\My Documents\Visual Studio 2010\Projects\red blue betting version\red blue betting version\main.cpp	50	1	red blue betting version"

but like, a hundred times
Last edited on
you're trying to add a string and an int, which is nonsense.

I can't tell what line of code is the culprit because none of your variables have meaningful names (t? b? r? what do those mean?) and you don't tell us what types they are (where are they defined?).

I would guess it's lines like this which are the problem:

t = t + b;

where 't' is a string and 'b' is an int.
thanks disch! and sorry the program was too big to be posted so i only posted that section. there are comments that tell you what t b and r are, but only in their decelerations. i will try these out
Topic archived. No new replies allowed.