Thread: Can anyone please help me with my code?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    91
    Okay.... I really can't find out whats wrong with my findDayCount function..
    Code:
    int findDayCount(struct month *m, char *user, int day){
    	int total=0;
    	int i;
    	int test=0;
    	// Checking to see if the enter_month is == to english or spanish
    	for(i = 0; i < 12; i++)
    	{
    		if(strcasecmp(user, m[i].nameEng) == 0)
    		{
    			strcpy(user, m[i].nameEng);
    			printf("You entered in the month, &#37;s, in english.\n", user);
    			fflush(stdout);
    			test = 1; break;
    		}
    		else if(strcasecmp(user, m[i].nameSpan) == 0)
    		{
    			strcpy(user, m[i].nameSpan);
    			printf("You enterd in the mont, %s, in spanish.\n", user);
    			fflush(stdout);
    			test = 1; break;
    		}
    		if(test == 0)
    		{
    			printf("That month cannot be found either in english or in spanish, please check your spelling.\n");
    			fflush(stdout);
    			return -1;
    		}
    	}
    	// Checking to see if the days are in the right range.
    	if(day > 31 || day < 1)
    	{
    		printf("There are no %d days in that month.\n", day);
    		fflush(stdout);
    	}
    	else if(day > 28 && ( (user == "february") || (user == "febrero") ) )
    	{
    		printf("There are no %d in the month, %s. There is only 28.\n", day, user);
    		fflush(stdout);
    	}
    	else if(day > 30 && ( (user == "april") || (user == "june") || (user == "august") || (user == "september") || (user == "november") ) )
    	{
    		printf("There are no %d in the month, %s. There are only 30 days.", day, user);
    		fflush(stdout);
    	}
    	else if(day < 1)
    	{
    		printf("There are is no zero day. Did you type in the day correctly?\n");
    		fflush(stdout);
    	}
    	total = m[i].numDays + day;
    	return(total);
    }
    it still tells me that I'm typing in the months wrong, except for january. Like january works fine.
    and the "total" comes out to be -1 or some weird number haha. RAWR~ lol

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Put "if (test == 0) ..." outside of the for-loop!

    Also:
    Code:
    (user == "february")
    tests if the address of user is the same address as the constant string "february". That is (nearly) impossible, as one is a local variable, and the other is a constant string value.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM