Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Text-based-game/alphabet.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
71 lines (60 sloc)
1.41 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "alphabet.h" | |
using namespace std; | |
const int alpha_max = 26; | |
string answer; | |
void sortstring(string &str) | |
{ | |
int charCount[alpha_max] = { 0 }; | |
for (int index = 0;index < str.length();index++) | |
charCount[str[index] - 'a']++; | |
for (int index = 0;index < alpha_max;index++) | |
for (int j = 0;j < charCount[index];j++) | |
{ | |
char c = ('a' + index); | |
answer += c; | |
} | |
} | |
void Alphabet :: random_word() | |
{ | |
cout << "To earn money type the letters of the following word in alphabetical order: " << endl; | |
string word_list[] = | |
{ "confinement", | |
"penitentiary", | |
"reformatory", | |
"guardhouse", | |
"punishment", | |
"conviction", | |
"imprisonment", | |
"incarceration", | |
"sentencing", | |
"criminology" }; | |
int word_index = rand() % 11; | |
string word = word_list[word_index]; | |
cout << word << endl; | |
sortstring(word); | |
} | |
void check(string &userin) | |
{ | |
JobMenu j; | |
PlayerMenu playermenu; | |
Sql sql; | |
if (answer == userin) | |
{ | |
cout << "Well done! You have completed all of the laundry. 5 pounds has been added to your account." << endl; | |
sql.updateBalanceCleaningTable(); | |
Sleep(2000); | |
playermenu.ppmenu(); | |
} | |
else if (answer != userin) | |
{ | |
cout << "Oh no! You have turned all of your inmates clothes pink! This will be deducted from your wages." << endl; | |
j.jobmenu(); | |
} | |
} | |
void Alphabet :: user_input() | |
{ | |
string userin; | |
cout << "Write the letters of this word in alphabetical order:" << endl;; | |
cin >> userin; | |
check(userin); | |
} |