Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
void process();
int intro();
void roof();
void floors(char, char, int);
void ground(char, char); // call for ground function
void sidingType(char *, char *); // 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: Rob's 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
return 0;
} //end if
else // begin if "no"
{
system("cls"); // clear screen
printf("\t Thanks for using Rob's Construction.\n"); //ending
printf("\tDon't forget to tell your friends about us!\n\n");
system("PAUSE");
return 0; //end program
} //end else
}
void process() // main process
{
int numFloors;
char siding, siding2;
numFloors= intro();
sidingType(&siding, &siding2);
roof();
floors(siding, siding2, numFloors);
ground(siding, siding2);
}
int intro() // intro & objective, and call for floor number
{
int numFloors ; //number of floors
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;
}
void sidingType(char *siding, char *siding2)
{ //start sidingType
int sidingChoice; // storing siding preference
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 (Lincoln 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;
default: printf("Invalid option selected, straight assigned\n");
*siding = '|'; *siding2 = '|';
} //end switch
} // end siding type
void roof() // 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 /|___|___|___|___|\\_|| \n");
printf("\t /__|TOTAL FLOORS|___\\_| \n");
printf("\t /__|___|_ _|___|__\\| \n" );
printf("\t /_|___|___|___|___|___|_\\ \n");
printf("\t /-------------------------\\ \n");
} //end roof
void floors(char siding, char siding2, int numFloors) //function floors with loop for # of floors
{
int floorCount;
for( floorCount=1; floorCount < numFloors; 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 %c\n", siding, 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
// initializing characer for right side
char play; // initializing characer for play
printf("\t %c %c\n", siding, siding2);
printf("\t %c GROUND FLOOR %c\n", siding, siding2);
printf("\t %c 1 %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|' ' / \\. ~ '|Rob | \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 Rob's Construction.\n");
printf("\tDon't forget to tell your friends about us!\n\n");
system("PAUSE");
} //end else
} // end ground