Problem with Strings

I am supposed to be writing a program for class, but I am having trouble with a string.

Here is the code so far:

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
//Todd Dunaway
//10/30/2014
//Chapter 4: If - Else Statements Program 4

#include <iostream>
#include <string>
using namespace std;
int main()
{
	int birthyear;
	string favfruit, beatlesfruit;
	beatlesfruit="strawberry";
	cout<<"In what year were you born?";
	cin>>birthyear;
	cout<<endl;
	if(birthyear<1970)
		cout<<"You qualify for the Juke Box Rally.";
		cout<<"What is your favorite fruit? ";
		cin>>favfruit;
		if(favfruit=beatlesfruit)
			cout<<"Strawberry Fields Forever";
		else
			cout<<"Bye, Bye Miss American Pie"<<endl;

return 0;

}


I am getting an error at "if(favfruit=beatlesfruit)".

The error I am getting is: Chapter 4 If - Else Statements Program 4.cpp:20:27: error: could not convert 'favfruit.std::basic_string<_CharT, _Traits, _Alloc>::operator=<char, std::char_traits<char>, std::allocator<char> >((*(const std::basic_string<char>*)(& beatlesfruit)))' from 'std::basic_string<char>' to 'bool'

Any help would be greatly appreciated.

Thanks,
Shawn E. Reynolds
Last edited on
You used the assignment operator in your if statement instead of the equals operator
Thank you, I did not notice that.
Topic archived. No new replies allowed.