#include <iostream> #include<iomanip> #include<ctime> #include<cstdlib> using namespace std; // Function prototype string create(); void hangman(int lives); void decision(int length,int cont); int main(){ string rand_word; char guess; int lives=7,cont=0; rand_word=create(); int length = rand_word.length(); char random[length] ; char dashes[length]; for(int i=0;i<length;i++){ random[i]=rand_word[i]; //just checking remove output afterwards; } while(lives!=0){ cout<<"guess a charcater: "<<endl; cin>>guess; bool a=true; for(int i=0;i<length;i++){ dashes[i]='_'; //CONTINUE FROM HERE; } for(int i=0;i<length;i++){ if(guess==random[i]){ cont++; hangman(lives); //do check prototype and insert lives in argument in case of an error; /* dashes[i]=guess; //instances CONTINUE FROM HERE cout<<dashes[i]<<endl; */ a = false; } } for(int i=0;i<length;i++){ if (a==true && guess!=random[i]) { lives-- ; hangman(lives); } } } cout<<"\n\n"; decision(length,cont); return 0; } string create(){ int size = 100 ; string arr[size]={"Accordion", "Bumblebee", "Chandelier", "Dandelion", "Ephemeral", "Fandango", "Gargoyle", "Hologram", "Iridescent", "Juxtapose", "Kaleidoscope", "Labyrinth", "Mellifluous", "Nebula", "Opulent", "Palindrome", "Quasar", "Rambunctious", "Sasquatch", "Tranquil", "Umbrella", "Vivacious", "Whimsical", "Xanadu", "Yodel", "Zenith", "Alabaster", "Buccaneer", "Capricious", "Dyslexia", "Ebullient", "Flibbertigibbet", "Gastronomy", "Halcyon", "Ineffable", "Jubilant", "Kowtow", "Lugubrious", "Misanthrope", "Nefarious", "Obfuscate", "Peregrinate", "Quintessential", "Rococo", "Serendipity", "Tintinnabulation", "Ubiquitous", "Vorfreude", "Wherewithal", "Xerox", "Yonder", "Zephyr", "Apotheosis", "Bibliopole", "Cacophony", "Dulcimer", "Ephemeral", "Furtive", "Gossamer", "Hapax", "Ineffable", "Juxtapose", "Kaleidoscopic", "Lilliputian", "Munificent", "Nebulous", "Obfuscate", "Peregrinate", "Quixotic", "Reticent", "Serendipity", "Tumultuous", "Umbra", "Voracious", "Whimsical", "Xenial", "Yesteryear", "Zephyr", "Aplomb", "Bibliopole", "Cacophony", "Dulcet", "Ephemeral", "Furtive", "Gossamer", "Hapax", "Ineffable", "Juxtapose", "Kaleidoscopic", "Lilliputian", "Munificent", "Nebulous", "Obfuscate", "Peregrinate", "Quixotic", "Reticent", "Serendipity", "Tumultuous", "Umbra", "Voracious"}; srand(time(0)); return arr[rand()%100]; } void hangman(int lives){ if(lives == 7){ cout<<" +----+\n"<< " | |\n"<< " |\n"<< " |\n"<< " |\n"<< " |\n"<< "-----------\n"; } else if(lives == 6 ){ cout<<" +----+\n"<< " | |\n"<< " o |\n"<< " |\n"<< " |\n"<< " |\n"<< " -----------\n"; } else if(lives == 5 ){ cout<<" +----+\n"<< " | |\n"<< " o |\n"<< " | |\n"<< " |\n"<< " |\n"<< " -----------\n"; } else if(lives == 4 ){ cout<<" +----+\n"<< " | |\n"<< " o |\n"<< " /| |\n"<< " |\n"<< " |\n"<< " -----------\n"; } else if(lives == 3 ){ cout<<" +----+\n"<< " | |\n"<< " o |\n"<< " /|\\ |\n"<< " |\n"<< " |\n"<< " -----------\n"; } else if(lives == 2 ){ cout<<" +----+\n"<< " | |\n"<< " o |\n"<< " /|\\ |\n"<< " / |\n"<< " |\n"<< " -----------\n"; } else if(lives == 1 ){ cout<<" +----+\n"<< " | |\n"<< " o |\n"<< " /|\\ |\n"<< " / \\ |\n"<< " |\n"<< " -----------\n"; } } void decision(int length,int cont){ if(cont == length){ cout<<"you have won: "<<endl; } else{cout<<"loser: "<<endl;} }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter