I am trying to make this Hangman silhouette:
But I am finding an issue with the printf
statement as it is taking the \
as a command for \n
instead of the right leg and for future code the right hand.
Anything I can do to fix it?
Code below is the hang man with no arms.
#include <iostream>
int main()
{
printf("\n --- \n| |\n| O\n| |\n| / \ \n|\n=========");
}
CodePudding user response:
you can use double \\ so it won't take it as an escape character. so your code will be:
#include <iostream>
int main()
{
printf("\n --- \n| |\n| O\n| |\n| / \\ \n|\n=========");
}
CodePudding user response:
Backslashes must be doubled in strings to appear as themselves. Also break the string into multiple pieces, one row per line for readability:
#include <stdio.h>
int main() {
printf("\n"
" --- \n"
" | |\n"
" | O\n"
" | /|\\\n"
" | / \\\n"
" |\n"
"=========\n");
return 0;
}
Or seen from the other side as in the picture:
#include <stdio.h>
int main() {
printf("\n"
" --- \n"
" | |\n"
" O |\n"
" /|\\ |\n"
" / \\ |\n"
" |\n"
"=========\n");
return 0;
}