i have this function that should compare values and return a string based on input from the main function. However it returns no value at all does anyone see and issue with it?


have checked all the input it is getting the correct values

highestMontName and averagedMonth are declared globally

month is a const int of 12


thanks for any ideas or help

string FindMax()
{
	string monthN;
	for(int i=0; i<month; i++)
	{
		if(averagedMonth[i]>highestMonthName)
		{	
			highestMonthName=i;
		}
	}

	//gets the month name
	if(highestMonthName == 0)
		monthN = "January";
	if(highestMonthName == 1)
		monthN = "February";
	if(highestMonthName == 2)
		monthN = "March";
	if(highestMonthName == 3)
		monthN = "April";
	if(highestMonthName == 4)
		monthN = "May";
	if(highestMonthName == 5)
		monthN = "June";
	if(highestMonthName == 6)
		monthN = "July";
	if(highestMonthName == 7)
		monthN = "August";
	if(highestMonthName == 8)
		monthN = "September";
	if(highestMonthName == 9)
		monthN = "October";
	if(highestMonthName == 10)
		monthN = "November";
	if(highestMonthName == 11)
		monthN == "Decemeber";

	return monthN;
}

Recommended Answers

All 6 Replies

try this.........

string FindMax()
{
	string monthN;
	for(int i=0; i<month; i++)
	{
		if(averagedMonth[i]>highestMonthName)
		{	
			highestMonthName=i;
		}
	

	//gets the month name
	if(highestMonthName == 0)
		monthN = "January";
	if(highestMonthName == 1)
		monthN = "February";
	if(highestMonthName == 2)
		monthN = "March";
	if(highestMonthName == 3)
		monthN = "April";
	if(highestMonthName == 4)
		monthN = "May";
	if(highestMonthName == 5)
		monthN = "June";
	if(highestMonthName == 6)
		monthN = "July";
	if(highestMonthName == 7)
		monthN = "August";
	if(highestMonthName == 8)
		monthN = "September";
	if(highestMonthName == 9)
		monthN = "October";
	if(highestMonthName == 10)
		monthN = "November";
	if(highestMonthName == 11)
		monthN == "Decemeber";

	return monthN;
}
}

Check line 36. I don't think it's the main problem, but it will catch up with you eventually.

Yep line 36.
Assignment operator needed not comparism.

monthN = "Decemeber";

instead

nice catch on that

Yep line 36.
Assignment operator needed not comparism.
C++ Syntax (Toggle Plain Text)

1.
monthN = "Decemeber";

monthN = "Decemeber";
instead

but still no luck with the other problem

copy and run my code. you should be ok with that.

haha it worked thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.