The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
I need help about FUNCTION
Discuss I need help about FUNCTION in the C Programming forum on Dev Shed. I need help about FUNCTION C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 9th, 2013, 08:52 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 13
Time spent in forums: 7 h 8 m 34 sec
Reputation Power: 0
|
|
|
I need help about FUNCTION
here is my screen output:
How am i gonna put them together? i mean side to side and not underneath of the other
here is my code:
Code:
#include <stdio.h>
#include <conio.h>
void paper()
{
printf(" _____\n");
printf(" / \\\n");
printf(" / ___/_________\n");
printf(" __/ \\\n");
printf("| |________/____\n");
printf("| \\\n");
printf("| |_____________/\n");
printf("| \\\n");
printf("| |___________/\n");
printf("| \\\n");
printf("|_ |_______/\n");
printf(" \\________/\n");
}
void rock()
{
printf(" _____\n");
printf(" / \\_______\n");
printf(" / \\ |\n");
printf(" __/ \\_____|\n");
printf("| \\ | |\n");
printf("| \\__|_____|\n");
printf("| | |\n");
printf("| |______|\n");
printf("| | |\n");
printf("|_ |______|\n");
printf(" \\__________/\n");
}
void scissor()
{
printf(" ___________________\n");
printf(" / \\ \\\n");
printf(" / \\ ________/\n");
printf(" __/ \\ |___________\n");
printf("| \\ \\ \\\n");
printf("| __\\ |_|___________/\n");
printf("| / \\_| \\\n");
printf("| \\_______/\n");
printf("| / \\\n");
printf("|_ \\_____/\n");
printf(" \\__________/\n");
}
main()
{
char p[2];
printf("\t\t\t\tJACK EN POY");
printf("\n\nBET OPTIONS");
printf("\n\n[S or s] = SCISSOR\n[P or p] = PAPER\n[R or r] = ROCK");
printf("\n\n\n\t\tPLAYER ONE's BET: ");
scanf("%s", &p[0]);
system("cls");
printf("\t\t\t\tJACK EN POY");
printf("\n\nBET OPTIONS");
printf("\n\n[S or s] = SCISSOR\n[P or p] = PAPER\n[R or r] = ROCK");
printf("\n\n\n\t\tPLAYER ONE's BET: ?");
printf("\t\tPLAYER TWO's BET: ");
scanf("%s", &p[1]);
system("cls");
//PAPER-ROCK CONDITION
if((p[0]=='P' || p[0]=='p') && (p[1]=='R' || p[1]=='r'))
{
printf("\t\t\t PLAYER ONE WINS! CONGRATULATIONS!\n");
paper(); rock();
}
else if((p[0]=='R' || p[0]=='r') && (p[1]=='P' || p[1]=='p'))
{
printf("\t\t\t PLAYER TWO WINS! CONGRATULATIONS!\n");
rock(); scissor();
}
//SCISSOR-PAPER CONDITION
else if((p[0]=='S' || p[0]=='s') && (p[1]=='P' || p[1]=='p'))
{
printf("\t\t\t PLAYER ONE WINS!CONGRATULATIONS!\n");
scissor(); paper();
}
else if((p[0]=='P' || p[0]=='p') && (p[1]=='S' || p[1]=='s'))
{
printf("\t\t\t PLAYER TWO WINS!CONGRATULATIONS!\n");
paper(); scissor();
}
//ROCK-SCISSOR CONDITION
else if((p[0]=='R' || p[0]=='r') && (p[1]=='S' || p[1]=='s'))
{
printf("\t\t\t PLAYER ONE WINS! CONGRATULATIONS!\n");
rock(); scissor();
}
else if((p[0]=='S' || p[0]=='s') && (p[1]=='R' || p[1]=='r'))
{
printf("\t\t PLAYER TWO WINS! CONGRATULATIONS!\n");
scissor(); rock();
}
/*condtion 4 if input is invalid or the same user input*/
else if((p[0]=='R' || p[0]=='r') && (p[1]=='R' || p[1]=='r'))
{
printf("\t\t\t\t IT's A DRAW\n");
rock(); rock();
}
else if((p[0]=='S' || p[0]=='s') && (p[1]=='S' || p[1]=='s'))
{
printf("\t\t\t\t IT's A DRAW\n");
scissor(); scissor();
}
else if((p[0]=='P' || p[0]=='p') && (p[1]=='P' || p[1]=='p'))
{
printf("\t\t\t\t IT's A DRAW\n");
paper(); paper();
}
else
printf("\n\n\n\t\t\t ERROR: INVALID INPUT");
getch();
return 0;
}
|

March 9th, 2013, 09:35 AM
|
 |
Contributed User
|
|
|
|
Do something like
Code:
char *paper[] = {
" _____",
" / \\",
" / ___/_________",
" __/ \\",
"| |________/____",
"| \\",
"| |_____________/",
"| \\",
"| |___________/",
"| \\",
"|_ |_______/",
" \\________/",
};
char *rock[] = {
" _____",
" / \\_______",
" / \\ |",
" __/ \\_____|",
"| \\ | |",
"| \\__|_____|",
"| | |",
"| |______|",
"| | |",
"|_ |______|",
" \\__________/",
};
Then in a loop, you can do
printf("%40s%s\n", paper[i], rock[i] );
|

March 9th, 2013, 09:45 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 13
Time spent in forums: 7 h 8 m 34 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by salem Do something like
Code:
char *paper[] = {
" _____",
" / \\",
" / ___/_________",
" __/ \\",
"| |________/____",
"| \\",
"| |_____________/",
"| \\",
"| |___________/",
"| \\",
"|_ |_______/",
" \\________/",
};
char *rock[] = {
" _____",
" / \\_______",
" / \\ |",
" __/ \\_____|",
"| \\ | |",
"| \\__|_____|",
"| | |",
"| |______|",
"| | |",
"|_ |______|",
" \\__________/",
};
Then in a loop, you can do
printf("%40s%s\n", paper[i], rock[i] ); |
THANK YOU! =)
|

March 9th, 2013, 11:18 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 13
Time spent in forums: 7 h 8 m 34 sec
Reputation Power: 0
|
|
|
any other solution? i couldnt let it work >_>
|

March 9th, 2013, 11:35 AM
|
 |
Contributed User
|
|
|
|
|
How about posting what you managed to achieve.
Then we can fix it.
> any other solution? i couldnt let it work >_>
Yes, the way I showed you, but implemented without the bugs you've put in.
|

March 9th, 2013, 11:46 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 13
Time spent in forums: 7 h 8 m 34 sec
Reputation Power: 0
|
|
i did it something like this
Code:
char paper(char x)
{
char *paper[]= {
printf(" _____\n");
printf(" / \\\n");
printf(" / ___/_________\n");
printf(" __/ \\\n");
printf("| |________/____\n");
printf("| \\\n");
printf("| |_____________/\n");
printf("| \\\n");
printf("| |___________/\n");
printf("| \\\n");
printf("|_ |_______/\n");
printf(" \\________/\n");
};
}
i feel that your solution is correct,perhaps i just dont know how to do it >_> kind of new in fucntions.
|

March 9th, 2013, 03:45 PM
|
 |
Contributed User
|
|
|
|
I said to put the strings in the arrays, not put the printf's in the arrays.
Then it's something like
Code:
void doPrint ( char *left[], char *right[] ) {
printf("%40s%s\n", left[0], right[0] ); // except you make this a loop!
}
And you call it with
doPrint(rock,paper);
|

March 9th, 2013, 04:15 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
Now that salem has explained the same thing to you for a second time, look at what he wrote, look at what you did, pay particular attention to how they differ.
|

March 9th, 2013, 11:14 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 13
Time spent in forums: 7 h 8 m 34 sec
Reputation Power: 0
|
|
|
i have not learned bout POINTERS yet, and we are only allowed to use functions. i really dont have an idea, what you had explained Salem
but thank you BIG TIME! you bothered to answer my query
|

March 14th, 2013, 11:57 AM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 16
Time spent in forums: 2 h 52 m 53 sec
Reputation Power: 0
|
|
|
The problem isn't with pointers, you're trying to store the printf's inside your array.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|