passing counters between function

This is a discussion on passing counters between function within the C Programming forums, part of the General Programming Boards category; Ugh...I don't even know why I'm bothering to continue arguing on this board when I said I was done with ...

  1. #16
    Registered User
    Join Date
    Feb 2004
    Posts
    26
    Ugh...I don't even know why I'm bothering to continue arguing on this board when I said I was done with the project several posts ago.
    Having just seen that your question was clearly answered in the first reply it's obvious that you have put zero effort into working out the solution.
    I put in several hours with the suggestions above (which you would have no way of knowing). And again, they were not pertaining directly to my question, nor was an explanation provided that told me what that was and how it worked. I've only been doing this 6 weeks and I obviously haven't grasped the concepts and the reasons behind how they work well enough to decipher an answer by code alone or I wouldn't be on this board.

    Finally, I'm only doing this class because I have to, not because I want to. It's my last class to graduate, and I don't plan on using this again. I don't want to cheat my way though...I'd like to have a basic understanding as to how it works. And by my first post, I think it shows I was doing a lot on my own. I was proud of how much I did to be so new at it. I thought that was a lot for a newbie. Apparently not.

    Sorry for my ignorance, people.

    And to finally close this subject, here is my final working code that I got from spending a couple of hours in the campus lab with my professor (who provided English words with metaphors to help break it down for a non-computer guy like me to understand).
    I'm hoping this code will 1) end this discussion and 2) give a final working solution for anyone needing help with a similar project. Sorry that I haven't taken the time to make it prettier.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    
    void process();      // call for process function
    int intro();         // call for intro function
    void roof(int numFloors);         // call for roof function
    void floors(int numFloors, char *siding, char *siding2);       // call for floors function
    void ground(char *siding, char *siding2);       // call for ground function
    void sidingType(char *siding, char *siding2);   // call for siding type function
    
    
    int main()           // main function
    {                    // begin intro
       char play;           // initializing characer for play   
       printf("\tWelcome to...\n");
       printf("\tBUILD YOUR DREAMHOUSE!\n\n");
       printf("\tBy: Stokes Construction Co.\n");
       printf("\tYou plan it, we build it!\n\n");
       printf("\tWant to start planning? y/n ");  // prompt for answer from user
       scanf("%c", &play);     // scanning answer from user
       fflush(stdin);          // flushing keyboard input
          if (play == 'y')     // begin if "yes"
          {
          process();           //call for process
          } //end if
           else                // begin if "no"
               {
              system("cls");   // clear screen
              printf("\t   Thanks for using Stokes Construction.\n");    // ending
              printf("\tDon't forget to tell your friends about us!\n\n");
    
              system("PAUSE");
              return 0;       // end program
           }  // end else
    }      // end main
    
    void process()        // main process
    {                     // start process
    
       char siding;         // initializing characer for left side
       char siding2;        // initializing characer for right side
       int numFloors = 0;   // number of floors
       int floorCount = 1;  // initializing counter to 1
       int sidingChoice;    // storing siding preference
    
         numFloors =  intro();        // starting intro and objective
          sidingType(&siding, &siding2);   // call for siding type and conversion
          roof(numFloors);         // call for roof
          floors(numFloors, &siding, &siding2);       // call for floors including loop
          ground(&siding, &siding2);       // call for ground
    }                     // end process
    
    int intro()          // intro & objective, and call for floor number
    {
       int numFloors = 0;
       system("cls");   
       printf("\t\t BUILD YOUR OWN HOME!!\n\n");     //start objective
       printf("\tThe purpose of this program is to demonstrate the four ways to use\n");
       printf("\ta function(), Switch/Case and pointers. This project will finish the\n");
       printf("\tintroduction of Structure, Selection and Looping you learned in\n");
       printf("\tCOP1000 Data structures and Algorithms class and apply how it\n");
       printf("\tapplies to the C programming language.\n\n");
       printf("\tThis program asks you for the number of floors, and type of siding\n\n");
    
       printf("\tHow many floors would you like your house to be? "); //prompt for # of floors
       scanf("%d", &numFloors);   // scan # of floors and add to numFloors
       fflush(stdin);
       printf("\t\n\n");
       return numFloors;
    }  //end intro
    
    void sidingType(char *siding, char *siding2)   // siding menu and concversion to type char
    {                   // start sidingType
       int sidingChoice = 0;
       system("cls");      // new screen
       printf("\t PLEASE CHOOSE YOUR SIDING TYPE:  \n\n");       // siding options
       printf("\t  \n");
       printf("\t 1. Straight (boring) siding | | \n");
       printf("\t 2. Brick (hurricane strength) siding [ ] \n");
       printf("\t 3. Log (Lincold style) siding ( ) \n");
       printf("\t 4. Stucko (too cheap for brick) siding { } \n");
       printf("\t 5. X (whatever this is) siding X X \n");
       printf("\t 6. Shinge (poop on a) siding / \\ \n\n");
       printf("\t Please enter your siding preference:  ");
       scanf("%d", &sidingChoice);    // read user siding preference
       fflush(stdin);
       printf("\t\n\n");
          switch( sidingChoice ) {     // start switch for conversion
             case 1: *siding = '|'; *siding2 = '|'; break;     // conversion to straight
             case 2: *siding = '['; *siding2 = ']'; break;     // conversion to brick
             case 3: *siding = '('; *siding2 = ')'; break;     // conversion to log
             case 4: *siding = '{'; *siding2 = '}'; break;     // conversion to stucko
             case 5: *siding = 'X'; *siding2 = 'X'; break;     // conversion to x
             case 6: *siding = '/'; *siding2 = '\\\'; break;    // conversion to shingle
             default: printf("Invalid option selected, straight assigned\n"); *siding = '|'; *siding2 = '|';
             }      // end switch
    }               // end siding type
    
    void roof(int numFloors)  // function roof
    {            // start roof
       system("cls");
       printf("\t                                                        \n");
       printf("\t                                     ,~ ~~ ,~ ~~~       \n");
       printf("\t                                 ,~ ~~ ~ ~~  ,~ ~~~~~   \n");
       printf("\t                                 ~~~ ,~ ~ ~~  ~  ~~     \n");
       printf("\t                       ^       ,~ ~~ ,~ ~~~     \n");
       printf("\t                      /_\\    _______           \n");
       printf("\t                     /___\\   |__|__|           \n");
       printf("\t                    /__|__\\  |_|__||           \n");
       printf("\t                   /_|___|_\\ |__|__|           \n");
       printf("\t                  /|___|___|\\|_|__||           \n");
       printf("\t                 /|__|___|__|\\__|__|           \n");
       printf("\t                /__|___|___|__\\|__||           \n");
       printf("\t               /_|___|___|___|_\\|__|           \n");
       printf("\t              /|__Total Floors_|\\_||           \n");
       printf("\t             /___|___ %2.2d  ___|___\\_|           \n", numFloors);
       printf("\t            /__|___|___|___|___|__\\|           \n");
       printf("\t           /_|___|___|___|___|___|_\\           \n");
       printf("\t          /-------------------------\\          \n");
    }               // end roof
    
    void floors(int numFloors, char *siding, char *siding2)   // function floors with loop for # of floors
    {
    int floorCount = numFloors;
    for( floorCount; floorCount > 1;  floorCount--)  //for loop
       {
       printf("\t          %c                         %c\n", *siding, *siding2);
       printf("\t          %c                         %c\n", *siding, *siding2);
       printf("\t          %c     |---|     |---|     %c\n", *siding, *siding2);
       printf("\t          %c     |   |     |   |     %c\n", *siding, *siding2);
       printf("\t          %c     |---|     |---|     %c\n", *siding, *siding2);
       printf("\t          %c                         %c\n", *siding, *siding2);
       printf("\t          %c                         %c\n", *siding, *siding2);
       printf("\t          %c      Floors: %2.2d         %c\n", *siding, floorCount, *siding2);
       printf("\t          %c                         %c\n", *siding, *siding2);
       printf("\t          %c-------------------------%c\n", *siding, *siding2);
       }              // end floor
    }                 // end floors
    
    void ground(char *siding, char *siding2)     // function ground
    {                 // start ground
       char play;           // initializing characer for play  
       printf("\t          %c                         %c\n", *siding, *siding2);
       printf("\t          %c                         %c\n", *siding, *siding2);
       printf("\t          %c                         %c\n", *siding, *siding2);
       printf("\t          %c        /======\\         %c\n", *siding, *siding2);
       printf("\t          %c         |----|          %c\n", *siding, *siding2);
       printf("\t          %c         |    |          %c\n", *siding, *siding2);
       printf("\t          %c         |   .|          %c\n", *siding, *siding2);
       printf("\t          %c         |    |          %c     \n", *siding, *siding2);
       printf("\t   @  @   %c         |    |          %c   @  @ \n", *siding, *siding2);
       printf("\t___|__|___%c-------------------------%c___|__|___ \n", *siding, *siding2);
       printf("\t '    .    '     . /      \\    '      .   '       \n");
       printf("\t   '         '    /        \\                 .    \n");
       printf("\t .  ~   '   '    /          \\   '   '    '     .  \n");
       printf("\t     '  .      ./            \\    .     .  ~       \n");
       printf("\t  '        '   /              \\    '         '    \n");
       printf("\t  .|Rob|'  '  /                \\.  ~  '|Stokes| \n");
       printf("\t================================================ \n\n\n");
       printf(" Would you like to build another house? y/n  ");
       scanf("%c", &play);        // read  player's response to playing again
       fflush(stdin);
    
          if (play == 'y')        // if statement for play again
          {
             process();           // call for prosess
          }                       // end if
          else                    // statement for not playing again
          {
             system("cls");
             printf("\t   Thanks for using Stokes Construction.\n");
             printf("\tDon't forget to tell your friends about us!\n\n");
    
             system("PAUSE");
          }  // end else
    }        // end ground

  2. #17
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    ROFLMAO!
    You said that we didn't answer your question yet in your last program it uses the VERY THING WE TOLD YOU TO USE.

  3. #18
    Registered User
    Join Date
    Feb 2004
    Posts
    26
    Yeah...too bad you didn't explain it where I could understand it. Your ability to make it work was never in question. My understanding that a pointer was necessary for the floor portion was also never in question. Your ability to help me understand how and why it works was in question.
    Apparently, the other posts were unclear. I need to know how and why, otherwise, I am learning nothing.
    Explaination, explanation, explaination.
    Just posting code and saying, "Now you go transcribe this" does nothing. That isn't help. That isn't teaching me. It's more like showing off. "Do this and then do this" might make it work, but what did I get? How can I apply it to anything else and build on it. It's like going, "Here is a hamburger...now that you see the end result, go make your own. " That's all I wanted ...the how and why. At a newbie level.

  4. #19
    Registered User
    Join Date
    Feb 2004
    Posts
    72
    Originally posted by BungleSpice
    Yeah...too bad you didn't explain it where I could understand it. Your ability to make it work was never in question. My understanding that a pointer was necessary for the floor portion was also never in question. Your ability to help me understand how and why it works was in question.
    Apparently, the other posts were unclear. I need to know how and why, otherwise, I am learning nothing.
    Explaination, explanation, explaination.
    Just posting code and saying, "Now you go transcribe this" does nothing. That isn't help. That isn't teaching me. It's more like showing off. "Do this and then do this" might make it work, but what did I get? How can I apply it to anything else and build on it. It's like going, "Here is a hamburger...now that you see the end result, go make your own. " That's all I wanted ...the how and why. At a newbie level.
    Can you post an article describing in laymans terms the answers to your questions? This way if someone else needs an answer they can be refered to your article.

    Thanks

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  3. Passing a byte and its bits to a function
    By rtarbell in forum C Programming
    Replies: 9
    Last Post: 12-04-2008, 08:24 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Passing a function to a function
    By lend0g in forum C++ Programming
    Replies: 1
    Last Post: 03-18-2003, 09:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21