C/C++ :: How To Keep Track Of Used Letters In Hangman Game
Oct 1, 2014
i am trying to make a hangman game. The game works fine so far but i cannot seem to keep track of the letters used. I have to prevent the user from using a letter that has already been entered by the user at some point in the game before. But can't seem to work my way around it. I have included the code below
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<ctime>
[Code].....
View 3 Replies
ADVERTISEMENT
Jun 2, 2013
designing an algorithm forHangman game.
I've got everything I need that is expected of my program except this.
When the user starts the game they will have these letters available to them:
"abcdefghijklmnopqrstuvwxyz"
Now if they were to guess 'a' it should look like this:
"-bcdefghijklmnopqrstuvwxyz"
then if they were to guess 'k':
"-bcdefghij-lmnopqrstuvwxyz"
and so forth.
View 3 Replies
View Related
Mar 21, 2013
I want to create a Hangman game with timer.. If the user cannot guess the word with in 1:30 min the game will stop and the word will be printed.
View 5 Replies
View Related
Mar 5, 2014
I'm making a hangman game. All i need to do is after the user guesses the letter correctly it replaces the stars with that letter. I have been trying for the past 2 hours and cant get it. So basically I have to do this. DisplayWord.replace(0, theWord(0)) but I don't know how to put it in.
This is my code:
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
[Code].....
View 2 Replies
View Related
Jun 25, 2014
Basically I have a text file called words. I'm supposed to extract a word randomly from the file and have the user guess the word according to the definition.
I'm having trouble matching the definition to the word from the text file.
Here's my code:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
int number;
int count = 0;
string word;
[Code] ....
Here is my text file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet
View 1 Replies
View Related
Sep 12, 2013
I am recreating a hangman game. I'm trying to generate a random number to choose which word from my words list to use and I've done it a billion times before just like this. So, here's my code:
#include <iostream>
#include <cstdlib> //standard library.
#include <ctime> //for random.
#include <fstream> //for reading and writing to a file.
#include <string>
using namespace std;
int main() {
int num_words;
string word[num_words];
[Code] .....
I have the text file "words.txt" info below.
5
dog
cat
horse
pig
bird
If I run the program as it is, I get a segmentation fault core dumped error, however, if I take all the stuff that reads in the words from the words.txt file, like so:
#include <iostream> //every program has this.
#include <cstdlib> //standard library.
#include <ctime> //for random.
#include <fstream> //for reading and writing to a file.
#include <string>
[Code] ....
it works correctly and generates a random number.
I'm using Linux Mint.
View 7 Replies
View Related
Dec 23, 2013
My question is how can i read one line from a ".txt" file? To be more clear, i'm trying to write a hangman game. Therefore I'm trying to get words from a "wordlist.txt" file i created. I know a little bit about ifstream, ofstream and fstream. So my function i created to get a random line from this txt (not-completed yet since i don't know how to get that randomized line);
void grw() {
int line;
srand (time(NULL));
line = (rand() % 7972) + 1;
ifstream wordlist;
wordlist.open("wordlist.txt");
}
I created a variable called 'line' for the line number and randomized it (there are 7972 words in ".txt" file). So what i want to do now is to get the word on that line.
View 4 Replies
View Related
Oct 31, 2013
I am trying to pull my words randonly from a wordbank .txt file and so far i have this
#include <iostream>
#include <cctype>
#include <fstream>
using namespace std;
string word;
char knownLetters[]; // The word could be of any length
int stages = 6; // Our hangman has 6 stages, so the player starts with 6 lives
[Code] .....
View 1 Replies
View Related
Jun 26, 2014
Ok here I have a program that reads a word from a text file randomly and matches it with the definition. The user has to guess what the word is according to the definition.
I'm having trouble with my for loop, I'm not getting any errors. But I just know something is off.
Here's my code:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
int number;
int count = 0;
int numOfGuess = 0;
[Code] ...
This is words.txt:
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet
View 1 Replies
View Related
Jun 25, 2014
Basically I have a text file called words. I'm supposed to extract a word randomly form the file and have the user guess the word. If they guess the word correctly in x number of tries they will receive the definition.
I'm having trouble receiving that random word and I'm getting the definitions from the file.
Here's my code:
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
[Code] ....
This is what is in the words.txt file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet
View 3 Replies
View Related
Feb 7, 2015
I am currently trying to read information from an ID3V1.1 tag in C. For this project we are not allowed to use any external libraries. All of the fields except for the track field read correctly. The last two lines are the ones giving me trouble. Whenever I run the program, I get a seg fault when it tries to get the track number. I tried to debug using gdb and it said the problem was happening on line 34 which is where the fseek is. It works for the other fields so I'm wondering why it is going wrong. Should I change the offset to something other than -128? But the whole tag is only 128 characters so I'm unsure what is going wrong.
Code:
Program received signal SIGSEGV,
Segmentation fault.0x00000034ff66edf1 in fseek() from / lib64 /
libc.so .6 Missing separate debuginfos,
use:debuginfo - install glibc - 2.12 - 1.132.el6_5 .3.x86_64(gdb) back
#0 0x00000034ff66edf1 in fseek () from /lib64/libc.so.6
#1 0x000000000040076f in main (argc=1, argv=0x7fffffffdf58) at id3tagEd.c:34 Code: Code: #include<stdio.h>
#include<string.h>
}
[code]...
View 2 Replies
View Related
Nov 19, 2013
I want to create an object that uses visual C#'s Numeric Up/Down and a Track bar.
The reason is that I have a GUI that uses lots of these linked together with events and I want a common event handler for all of them.
Maybe just adding a property that is a Numeric Up/Down in the Track bar and vice-versa will allow me to create a common event for all of these pairs.
View 1 Replies
View Related
Mar 4, 2014
I need writing my header files for my program of hangman. I've written what I could, but when I try parts out on their own to see if they work, I get errors. I haven't written my driver yet since I wanted to get this header working first. The first function needs to take the name of the file and read in its contents into the globally declared array. The second function takes no arguments and returns a word from the word list chosen at random. I guess my question is, would what I have so far work, or am I completely off? Here's what I have so:
randword.h
#ifndef _randword_h
#define _randword_h
//static char words[100][50];
/*
*Function: InitDictionary
*This function reads in the dictionary of words and puts them into an array. */
void InitDictionary(void);
[Code] ....
View 14 Replies
View Related
Oct 14, 2013
does a pointer keep track of time stamps when it is created? i am trying to use it to create a table that can store the access count and the temporal locality at the same time.
View 5 Replies
View Related
Dec 11, 2013
[URL] ....
This is my code, but how can I implement this?
View 1 Replies
View Related
Feb 19, 2014
I would like to track user actions within my windows desktop application, and write them to a database.
I also have a User class, that has a userID field pulled from the User table. I can write a login event (UserID, timestamp, action) with no problem, but as the user navigates around the app, how can I persist the user object so I always have access to their userID? I know I can just pass it as a parameter as they do different tasks, but that seems inefficient to me.
View 7 Replies
View Related
May 4, 2013
I have a set of n- dimension point store in `vector< vector<double> >`
ex A[0][1].............[N], and A[0][0] = X, A[0][1] = Y, A[0][2] = Z
and I want to sort the vector of all of the dimension
ex sort X, Y, Z ,.........N in ascending order
ex A[0] = (1,5,3), A[1] = (3,2,1) A[2] = (2,8,4) after sorting
index: 0 1 2
A[0] = (1,5,3), A[1] = (2,8,4) A[2] = (3,2,1)
original index : 0 2 1
I find that `sort(vector.begin(), vector.end())` can sort it but how can I record the original index with a additional vector?
Is there a algorithm or C++ feature can solve it?
I have tried to solve it with a class wrapper it but I don't know how to write the compare function.
class point{
public:
point(int totalLength = 0, int elementLength = 0);
vector<vector<double> > pointSet;//store the n-D points
vector<double> pointIndex;//store the index
};
point::point(int totalLength, int elementLength){
pointSet.resize(totalLength,vector<double>(elementLength, 0));
pointIndex.resize(elementLength);
}
View 3 Replies
View Related
Jun 27, 2013
I am trying to write a program that keeps track of social security numbers of customers I have to assume that its a four-digit number. When the program runs,it has to prompt that the user should enter a 4-digit number to record, or 0 to exit.
The program also needs to be able to give an error message if a certain number is entered more than once.
After all the numbers have been saved and you finally end it by pressing 0, it needs to be able to output all the entered SSN's.
Here is my code so far:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
bool isExist(int ssn, int records[], int numberOfRecords);
[Code] ......
View 3 Replies
View Related
Oct 4, 2014
In this assignment, you are going to write a program that keeps track of the social security numbers (SSN) of customers of a bank. Please notice that we are going to assume that SSN is a four-digit number (e.g., 1234. 0123 is not allowed.). When the program runs, it prompts that the user should enter a 4-digit SSN number to record, or 0 (zero) to exit.
So far I have this:
#include <iostream>
using namespace std;
bool isExist(int ssn, int records[], int numberOfRecords);
int main(){
int ssn = 0;
int records[32];
[Code] .....
View 16 Replies
View Related
Sep 27, 2014
I wrote a code that mimics a dice, my code so far will ask for the user to input a number at which they want to hold or no longer throw the dice, it will also ask the user how many roll simulations they would like to do.
If a 1 is rolled the turn is over and the score is 0
After this input is recieved the code goes into a loop until the values have been met.
I would to add probability to my code so I need to know how many times a certain number was rolled and this is where I am stuck.
An example of how I would like my code to work, let's suppose hold at number is 17
We role the dice until we roll a 17 or larger, but if we roll a 1, then our score is 0.
Let's suppose the number of simulations is 5 and for simulation 1 we roll
2 + 5 + 6 + 4 = 17
and for simulation 2 we roll
5 + 4 + 1, but since we rolled a 1, the score is 0,
for simulation 3 we roll
3 + 4 + 5 + 6 = 18
for simulation 4 we roll
4 + 4 + 6 + 6 = 20
for simulation 5 we roll
3 + 4 + 5 + 5 = 17 so that means we got
0: 1 time 1/5 = .20
17: 2 times 2/5 = .40
18: 1 time 1/5 = .20
19: 0 times 0/5 = .00
20: 1 time 1/5 = .20
21: 0 times 0/5 = .00
22: 0 times 0/5 = .00
In other words the idea is to roll a 17 or larger (or whatever the hold number happens to be), but if you roll a 1, then your score is a 0.
#include <iostream>
#include <cstdlib>
#include <ctime>
using std::cout;
using std::cin;
using std::endl;
int dieRoll();
[Code] ....
View 4 Replies
View Related
Jun 26, 2013
I am trying to write a program that keeps track of social security numbers (SSN) of customers of a bank. I have to assume that SSN is a four-digit number (e.g., 1234. 0123 is not allowed.). When the program runs,it has to prompt that the user should enter a 4-digit SSN number to record, or 0 (zero) to exit.
The program also needs to be able to give an error message if a certain number is entered more than once.
After all the numbers have been saved and you finally end it by pressing 0, it needs to be able to output all the entered SSN's.
Here is my code so far :
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
bool isExist(int ssn, int records[], int numberOfRecords);
void listRecords(int records[], int numberOfRecords);
int main()
[Code]...
View 2 Replies
View Related
Jan 8, 2014
I'm trying to keep track of the size of blocks of memory that a pointer points to. No matter what I do, this code below always outputs the integer 8.
If I change 1000 to 5, I still get 8. If I change it to 0, I get 8... If I change it to -1, I get 8. If I change int *a to double *a, I get 8. If I take away the & symbol, I get 8. If I use *& instead, I get 8.
Why? I want it to output 1000. If I change that to 500, I want it to output 500.
int *a;
a = malloc(1000 * sizeof(int));
int j = sizeof(&a);
printf("%d", j);
I want to build my skills where I can allocate, inspect and change memory sizes.
View 4 Replies
View Related
Dec 21, 2014
I'm working on my first video game. So far I have a few classes in the game starting with the Game class which includes a list of GameObjects (another class). There are several classes that inherit from GameObjects used to implement things like bullets, explosions, various enemy types, etc.
The game essentially iterates through the list of GameObjects to update/render them. I would like to provide access to the Game's list of GameObjects inside another class (like the Bullet class) so I can put new objects on the list. For example, when a bullet hits, I want to add an explosion to the Game's GameObject list it can be updated/rendered.
How this should be setup? I was considering adding a pointer to the Game or GameObject list to the GameObject class (and methods to access it), but I was wondering if there is a better way to set this up?
View 4 Replies
View Related
Sep 13, 2014
I would like to make a program for calculating the total price of a game station, and a game. I made a program like this for just the price of a game in class, but I want to make one that does the game system as well.
View 7 Replies
View Related
Mar 16, 2013
I'm just trying to find out if the way I've setup my code currently allows me to count the letters as they occur? I don't yet see how to do it but I need clarification. Ideally the function letterCounter would do the counting but atm I'm just trying to figuring it out in the display function.
View 2 Replies
View Related
Jan 26, 2013
Code:
#include<stdio.h>
#include<string.h>
#define a 9
#define b 9
#define c 3
int main() {
[Code] .....
In practice section there was a challenge to print up numbers in letters up to billion including negatives I didn't look at the solution and came up with this but it is getting difficult after this point....
View 9 Replies
View Related