Thread: help with a fuction

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    help with a fuction

    need a function when given an int between 0 and 6 prints the day of the week need help plzzzzzzzzzzzzzzzz

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Get writing your own stuff.... post here when you have problems coding it. Show a little effort and people will be willing to help you.

    Read the guidelines about homework.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    ?

    i just need a little bust start i dont really no what to do really new just need some plzzzzzzzzzzzzzzz

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    ?

    thjis dealing with the fuction probleum plz help

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Why don't you start with a tutorial, or maybe a good C++ book.

    There are various ways to do what you're asking, why not do a bit of research yourself and see what you can come up with.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    edit: the stupid thing has messed up the string literal slightly. it should read
    "SundayMondayTuesdayWednesdayThursdayFridaySaturda y"
    editX2: wtf? why cant i get rid of the space, oh well, anyway, there should be no space before sunday
    Code:
    #include <stdio.h>
    
    const char *daydata =
    "SundayMondayTuesdayWednesdayThursdayFridaySaturday";
    
    int daylengths[7] = {6, 6, 7, 9, 8, 6, 8};
    
    void dayname (int day, char *p)
    {
      int offs, i;
      for (offs = 0, i = 0; i < day; offs += daylengths[i++]);
      (void) memcpy (p, daydata + offs, daylengths[i]);
      *(p + *(daylengths + i)) = '\0';
    }
    
    int main (void)
    {
      int j = 0;
      char buff[20];
      for (j = 0; j < 7; j++)
      {
        dayname (j, buff);
        (void) printf ("%s\n", buff);
      }
      return printf ("Done!\n");
    }
    hello, internet!

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    93

    wow

    wow.. talk about lazy...

    Code:
    void displayDay(int);
    
    void displayDay(int Input)
      {
        switch(input)
          {
             case 0: cout << "Monday";
                          break;
             case 1: cout << "Tuesday";
                          break;
          }
        return ;
       }
    or
    Code:
    void displayDay(int);
    
    void displayDay(int Input)
      {
         if (Input == 0)
           cout << "Monday";
        else if (Input == 1)
           cout << "Tuesday";
       return ;
       }
    or
    Code:
    enum Days{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}
    
    Days Input;
    Input = Monday;      // Input = Monday;  or Input = 0;
    Input = Days(4);      // Input = Friday; or Input = 4;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Finding the mode, calling fuction
    By CaliJoe in forum C++ Programming
    Replies: 5
    Last Post: 04-09-2009, 08:50 PM
  2. Einstine calculator
    By Mach_ie in forum C Programming
    Replies: 2
    Last Post: 08-30-2003, 09:37 AM
  3. Enistine program
    By Mac_the vamp in forum C Programming
    Replies: 2
    Last Post: 11-11-2002, 10:56 AM
  4. check for number of days as a fuction?
    By scronge1 in forum C++ Programming
    Replies: 4
    Last Post: 06-24-2002, 06:35 AM
  5. just a fuction problem
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 05-05-2002, 04:01 AM