compile error (else if statements)

I'm working on an assignment that asks the use for a single input that represents both month and day ( mm.dd ), this is the code that i have come up with but it is not compiling its giving me 3 errors , on my last if statement and my last two else if statements.

( they go something like this "error: could not convert ‘season.std::basic_string<_CharT, _Traits, _Alloc>::operator=<char, std::char_traits<char>, std::allocator<char> >(((const char*)"Winter"))’ from ‘std::basic_string<char>’ to ‘bool’
if ( season = "Winter"){"

not sure what to do now i'm stuck , would appreciate any help, thank you.

(complete noob i know the format that i have for my code is terrible i'm working on it i promise lol.)

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
 #include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;


int main() {
	string season;
	double date = 0;
	cout << "I will print the four seasons.\n\n";
	cout << "Enter the date as mm.dd: ";
	cin >> date;
	int month = date;
	int day = (date - month) * 100 + 0.5;
	if ( month <= 3) {
		season = "Winter";
	} else if ( month >= 4 && month <= 6){
		season = "Spring";
	} else if ( month >= 7 && month <= 9){
		season = "Summer";
	} else if ( month >= 9 && month <= 12){
		season = "Fall";
	}

	if ( (month % 3) == 0 && day >= 21){
		if ( season == "Winter"){
		season = "Spring";
	} else if ( season == "Spring"){
		season = "Summer";
	} else if ( season == "Summer"){
		season = "Fall";
	} else {
		season = "Winter";
	}
}
		cout << "The season is " << season << endl;


    return 0;
}
Last edited on
You forgot to #include <string>

if( season = "Winter" ) if( season == "Winter" )
Last edited on
wow thank you so much , its compiled now and working :)

kind of lol i just have one more problem, when im setting the month to be divisible by 3 and the day to be >= 21 the value of the string season isnt changing from "Winter" to "Spring" any idea why? i feel like its because of the way that ive nested my if statements in line 25 and 26, is it okay to put two if statements in a row like that?
 
if ( month % 3 && day >= 21){

If the month is divisible by 3, there is no remainder, thus month % 3 evaluates to 0. When implicitly converted to a bool, it turns out to be false.
Last edited on
awesome I've updated line 26 to if ( (month % 3) == 0 && day >= 21){
and it works perfectly thank you so much for your help, you've saved me a big head ache and have granted me more hours of sleep :D again thanks a lot! You're the best!!!
No worries, buddy. :)
Topic archived. No new replies allowed.