C++ :: Hangman Game With Word Bank Input From TXT File

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


ADVERTISEMENT

C++ :: Hangman Definition Game - Extract Word Randomly Form File And User Guess The Word

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

C++ :: For Loop In Hangman Game - Read A Word From Text File Randomly And Matches It With Definition

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

C++ :: Match Word To Definition Hangman Game

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

C++ :: Hangman Game - Reading One Line From TXT File

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

C :: Create A Hangman Game With Timer

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

C++ :: Algorithm For Letters Used In Hangman Game?

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

C++ :: Replacing String In Hangman Game?

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

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 View Related

C++ :: Hangman Game - Generating Random Number

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

C++ :: Math Game Program - Stuck On Input File

Oct 21, 2013

I am making a math game program that simple and need to have a user input a name and then that name.txt is brought up and use variables from the text to add to their score. heres my code kinda long.

#include <iostream>
#include <cmath>
#include <cctype>
#include <string>
#include <ctime>
#include <cstdlib>

[Code] ....

View 10 Replies View Related

C++ :: Read Story From Input File / Separate Words And Output Lines On Which The Word Occurs

Feb 21, 2014

I have program that is supposed to read in a story from an input file and separate the words and output the lines on which the word occurs. It needs to read in another input file that has a list of words (1 per line) to ignore. i.e. skip them when running through the story. This is what I have so far, I've changed multiple things trying to get it running....

#include<iostream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<string>
#include"split.h"

[Code] .....

View 1 Replies View Related

C++ :: Word By Word From A Line In File?

Aug 14, 2014

ow to read word by word from a line in file into struct. Say for example:

12345 Joe Lim KH879.00
12233 Kay Suet Yee35.98

to

struct master {
unsigned short int IDnum;
char name[30];
float salesCustomer;
};

View 1 Replies View Related

C++ :: Capitalize Every Other Word In A User Input String

Nov 14, 2014

I've been agonizing over this all day. The assignment is to capitalize every other word in a user input string.

My logic is as follows:

1. I have the program get each character until it encounters white space (using for loop)
2. Then it should capitalize each character after the white space until it encounters another white space (using while loop).

My problem though is when i try to create a condition for while loop i have to terminate is when white space is encountered, but the very first character to start the while loop is a white space..

I was told to define boolean values, but after trying a few boolean conditions I'm still stuck..

Code:
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

[Code] .....

View 5 Replies View Related

C :: Program To Capitalize Every Other Word Of User Input

Feb 26, 2013

I'm trying to write a program that capitalizes every other word of a user output. (ex: if input is "i love you", the output is "i LoVe YoU").

I am using a for loop (although an if loop might be easier?) and I'm assuming that it is possible to write this program using a for loop (although I may be wrong--maybe only if loops can write this program). I have everything down EXCEPT the last step where I have to print the entire sequence. What i have so far is:

Code:
#include <cs50.h>
#include <stdio.h>
#include <string.h>
{
// get user input
printf("Type a sentence: ");
string s = GetString();

[Code] .....

The code above basically only prints out the capital letter (ex: input is "hello", output is "EL"). I don't know how to print out the entire sequence.

View 2 Replies View Related

C :: Get Text From Input And Save Each Word With Malloc

Dec 19, 2014

I want to write a program which takes a text from input and saves each word with malloc. For example for text "Have a nice a day" i want an array for each word, have,a,nice etc.

View 1 Replies View Related

C :: Take User Input Between 1 And 10 And Print Out Number As A Word

Oct 2, 2014

I'm working my way through some C exercises to get some practice and have hit a wall. I need to use a function to take a number, such as 1, and print out One.Here's what I've got so far:

Code:
#include <stdio.h>
int name(int n);
char numberOne[] = "One";
int main(void)
{
int n;
}

[code]...

However, when I run the code and enter "1" the only thing that gets printed to the screen is "(lldb)". I've tried changing it to doing it without variables and just printing "One" but that gave the exact same result.

View 6 Replies View Related

C++ :: Take User Input As String And Test To See If Matches A Word

Dec 4, 2014

I'm creating a program that takes user input in the form of a string and tests to see if it matches a word. Each correct word will increase their score by one. Here is a portion of the code that is not working.

...
else if(s == 32) {
if(!currentLetter.empty()) {
currentLetter.erase(currentLetter.length() - 2, currentLetter.length() - 1);
} if(currentLetter.compare(oWord) == 0) {

[Code] .....

To me, this looks like it should do a very simple task as intended-take a String, compare it to another, and reset the word if they match or output incorrect if not. But, I'm not sure if there is some quirk in C++ with Strings, because this code always outputs Incorrect. Please try again. and the score never increases. I also tested this by literally setting the strings equal in the code, which still resulted in it not doing what it's supposed to.

View 3 Replies View Related

C :: Make First Letter Of Each Word In User Input Text Uppercase

Sep 22, 2013

I need to write a C program to make the user input some text,and the first letter of each word has to be uppercase.(have to use while loops)So for example lets say the user inputs:

i lOvE pRoGrAmMiNg
The output needs to be:
I Love Programming

Code:

#include <stdio.h>
int main()
{
int i = 0;
char c, lower_c;

printf("Enter text
");

[code]....

I have started this code by making the letters lowercase.I am not sure how proceed after this step, the step of making the first letter uppercase.

View 2 Replies View Related

C++ :: Input String And Then Convert Each 1st Letter Of Word Into Capital Case

Dec 10, 2014

Write a program that inputs a string and then converts each 1st letter of a word in the string into capital case. An example run of the program is shown below:

Enter string: introduction to programming
Output string: Introduction To Programming

View 1 Replies View Related

C++ :: Text Adventure Game - Converting Input To Uppercase?

Jul 16, 2014

I'm trying to create a sort of text-adventure game, but rather than having to check for the input being uppercase or lowercase, I'd rather convert it before checking it in an if statement.

I've created a function, and I know it works because when I print the output, it shows up capitalized, however when I check it with an if statement, it doesn't pass.

Here is my code:

#include <iostream>
using namespace std;
void stringUppercase(string x) {
int i;
for (i = 0; i < x.length(); i++) {

[Code] ....

View 4 Replies View Related

C++ :: Bank Accounts Program Using Structures

Mar 1, 2014

I have an assignment to write a program using structures, getting input from a .txt file and output in text file as well. I have written a program that only reads and prints the data. I am trying to test if it works fine or not. I always comment an unnecessary code but still it wont compile. Now whats wrong with this program?

/* Bank Accounts Program */
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>//needed to use system() function
using namespace std;
const int MAX_NUM = 50;
void menu();

[Code]...

View 1 Replies View Related

C++ :: Creating Bank Accounts Using Classes

Feb 25, 2014

I am creating a bank account using classes. I have created the classes and now implementing them in my main program. I haven't written anything in the withdraw, find acct and all functions except "read account: read_acct()" because i wanna test if it reading the data from my .txt file or not. Dont know whats wrong with the program its not executing. Would let know that i'm new to classes and objects. Following is the code:

****************************************************
*************MAIN PROGRAM*************************
****************************************************
****Bank Accounts.cpp****

[Code]....

View 5 Replies View Related

C/C++ :: Calculating Interest Earned On Bank-account

Oct 21, 2014

This exercise should familiarise you with loops, if-then-else statements, and recursion. You will have to design and implement a program that calculates the interest earned on a bank-account. Deadline is the end of Tuesday in week 4.

Interests are compounded; that is, you earn interest on interest. Given a yearly interest rate of say, 6%, you can calculate the total sum available when an initial sum of 4000 pounds is put away for 13 years as follows:

4000 * ( (1 + [6/100])^13 ) = 8531.71 pounds

where the caret symbol denotes 'to the power of'. One way to calculate the power is by repeatedly mulitplying. Ie, you can mulitply 1.06 with 1.06 12 times to calculate 1.06^13.

PART 1

Design and implement a function that raises X to the power Y for a real number X and a positive integer Y. The function must use a while loop.

Design and implement a main program that calculates the sum availble when 1000 pounds has been put away for 25 years with 5 percent interest.

Change the while-loop in the function to a for-loop.

View 12 Replies View Related

C++ :: Mini Bank Account System - Using Header Files?

Feb 13, 2013

i am currently doing a mini bank account system using visual studio...i need using the header files...the question requires to use 3 header files for each class.these are the classes:

a)Accounts
b)CurrentAccounts
c)SavingAccounts

i have done the first part... how to do a new class in a different header file..

View 3 Replies View Related

C++ :: Error In Classic Bank Teller Simulation Program?

Feb 17, 2014

Anyhow, I have a program due Wednesday that is along the lines of the classic Bank Teller simulation using Queue's.

Unlike most of these programs, I have to integrate my own Queue, QueueNode, Teller, and Customer classes. I have attached all of these headers below plus the main file.

Now the error: While I'm sure there are other issues with the code, it will not let me create a new customerQueue (of Queue type) object as such:

Queue<Customer> customerQueue;

The error it is giving me is:

no matching constructor for initialization of 'Queue<Customer>'

Here is my code:

Queue.h:

#ifndef QUEUE2_H_
#define QUEUE2_H_

#include <iostream>
#include "Teller.h"
#include "Queue.h"

[Code] ....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved