C++ :: Correct Guesses Before Game Was Over - Save To A Text File

Feb 12, 2013

cout << "You've made 3 mistakes ! Game is now over !" << endl;
cout << "You had " << correctGuesses << " correct guesses before the game was over" << endl;
this info into a text file...

example of a guessing game code...

#include <iostream>
#include <time.h>
using namespace std;
int main() {

cout << "This is a very simple number guessing game. Each time you will be given a number of the range 0-10." << endl;
cout << "The objective of the game is to guess whether the next number is going to be higher or not. As simple as that." << endl;

[Code] ....

View 1 Replies


ADVERTISEMENT

C++ :: Create Save File For A Game That Is Not A Separate File?

Oct 10, 2014

How do you create a save file for a game, that is not a separate file? Specifically I am using code::blocks and sfml 2.1 to make a game and it saves to a text file at the moment. My problem is that it is very easy to modify the text file, and it is annoying to have to copy and paste several files if you want to use a copy of the game. I have a feeling that it may be to do with resource files, but I'm not exactly sure how to get these to work or whether you can modify them dynamically.

View 6 Replies View Related

C++ :: How To Save Two Arrays Into One Text File

May 11, 2013

I have a 4*4 array and a 8*8 arays in my c++ program and i would like to save those arrays in one textfile. How do i do that.

View 5 Replies View Related

C# :: How To Save Text From Listbox To The Txt File

Apr 19, 2014

I tried to save some data from my listbox to the text file, but didn't work... I think I tried many combination for code but still didn't work. what to do?

FileStream fs = new FileStream("tx.txt", FileMode.Create);
StreamWriter sr = new StreamWriter(fs);
sr.Write(listBox1.Text); //there is that problem, but I'm not sure how to write for success
sr.Close();

View 4 Replies View Related

C :: Create A File And Save Text In It In PDF Format

Feb 13, 2014

My objective is to create a file and save some text in it. But the twist is that file should be created in pdf format.

I have written following code:

Code:
#include<stdio.h>

Code:
int main() { FILE *fp;
char ch;
fp=fopen("file.pdf","w");
fprintf(fp, "%PDF-1.3"); //to initiate data storage in pdf file
printf(" Enter data to be stored in to the file:");
while((ch=getchar())!=EOF)
putc(ch,fp);
fclose(fp);
return 0;}

Now my file is created in pdf format, but when I open it by double click on it, it is not open and gives the message like: "Error in opening document. This file is damaged and could not be repaired."

View 1 Replies View Related

C++ :: How To Save File Directory To Text File Using Ofstream

Jul 22, 2013

I'm having a little problem with std:fstream - in my program, the user selects the location of a file which I want to remember. So, I have something like this:

Code: std::string fileLocation;
//Code here creates an 'open file' dialog box which lets the user choose which file to open.
//The string 'fileLocation' now contains the path to the chosen file.
std::ofstream prefs("prefs.txt");
if (prefs.is_open())
{
prefs << fileLocation;
prefs.close();
}

This works fine if the file chosen is in the same directory as the program, however, if they try to choose a directory outside of where the program is kept, it saves the text file into that directory instead of the same one as the program. So, it looks like outputting a directory into an ofstream actually changes the location to which the file is saved.

Is there a way to save the file directory to a text file using ofstream and still have the text file save in the same directory as the program?

View 5 Replies View Related

C# :: Save And Upload Data Table From A Text File

Jul 12, 2014

I am having a lot of trouble trying to save and upload a data table from a text file ,the data table which is bound to a datagrid, creates its own columns at the formloading event, and everytime a user clicks a button row is added to the data table. With the loading i put this code which i thought would read a text file and put all the content my datatable however a exception pops up saying Duplicate Name exeption. Heres the loading piece of code :

{
string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\DG1.txt ";
if(File.Exists(filePath))
{
StreamReader reader = new StreamReader(filePath);
string line = reader.ReadLine();

[Code] ....

View 11 Replies View Related

C :: Correct Answer Does Not End Game

Feb 21, 2013

Okay so I thought I had this assignment completed properly last week. Last night I found a bug while playing the game.why won't the game end when the player guesses the correct number? The game allows you to finish using the max number of guesses even though you already guessed the correct number.

Code:

#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define MAXGUESSES 6
#define MAXGAMES 20
#define MAXNUMBER 100
}

[code]....

View 9 Replies View Related

C++ :: Tic Tac Toe Console Game - If Statement Does Not Make Correct Decision

Feb 18, 2015

I recently wrote a "Tic Tac Toe" console game, and i seem to have a problem in my winning conditions, as when it checks if the player won (should have won) it doesn't take the appropriate action.

The winning conditions are in CoreLogic.cpp

here's the code, might not be the most pretty and clean code ever but it works for me.

there are more files i just didn't feel the need to include them all since the problem is only within CoreLogic.cpp and possibly in main.cpp

pos1-pos9 have been declared in the UserInterface.cpp and are being used to determine the correct decision to do within CoreLogic.cpp

Nothing happens when you win at this point it just exits the program.

View 19 Replies View Related

C :: Save And Load Game

Nov 26, 2013

I am trying to put my Save and Load function in my game, this is what i have:

Code:
/* Save game */
void GuardarJuego() {
FILE *fsave;
char turno;
fsave=fopen("SAVE.txt", "w");
fputs(*****, fsave);

[Code] .....

My game code is this: [C] GameCode - Pastebin.com

View 8 Replies View Related

C++ :: Video Game - How To Set Up Save System

May 20, 2013

I would like to create a video game. It would be text based. How could I set up a save system? Also, how would I load it?

View 3 Replies View Related

C/C++ :: How To Deserialize Save Game Data (specifically Skyrim)

Jul 29, 2014

I'm working on my first own project which is to collect some info from a save game file and then parse it to a website. Skyrim uses a .ess file extension, which to my knowledge is a binary file. I know how to open a file for reading but how to extract the info I need from there. Do all games use a standardized serialization or can the format of this file be anything?

If reading the binary file turns out to be too difficult, would it be possible to hook the game and retrieve info that way? If so, where would you recommend to start learning that stuff?

View 1 Replies View Related

Visual C++ :: Unable To Save File Using Cfiledialog Save As In MFC

Nov 5, 2013

I am trying to develop a GUI using MFC, but I am having trouble using CFiledialog to save a file. The problem is, the file is not getting saved to the folder when I use the CFiledialog. Below is the code I am using.

Code:

CString szFilter = "XNRep Files (*.xnrep)|*.xnrep||";
CString s = "xnrep";
CString t = "";
CFileDialog fileDlg(FALSE, s, t, NULL, szFilter);
if(fileDlg.DoModal() == IDOK)
{
std::ofstream file;

[Code]....

After the file dialog opens up, I enter the name of the file and select OK button. But the file does not show up in the directory I am saving to.

View 4 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++ :: Save Top 10 Scores In Simon Game - Filling Array Not Working Correctly

May 17, 2013

I wrote a Simon game, and wanted to save the top 10 scores. I was working right, until I decided I wanted to still be able to read the file if someone enters a name containing spaces. Now, the results aren't right.

void FillScoreList(string Simon_Names[], int Simon_Scores[]) {
ifstream Simon_HiScores("Simon_Data.txt");

if (Simon_HiScores.is_open()) {
for( int x=0;x<10;x++){

[Code] ....

Even without trying to read names with spaces, I'm getting

dad 1
0
340176
0
... either a long number or a zero. No names

View 4 Replies View Related

Visual C++ :: Puzzle Game - Implement A Way To Save Board State Throughout User Inputted Path

Mar 16, 2013

I've been trying to figure out how to implement a way to save this board state throughout a user's inputted path. At the end, I need the output to print out the board states (user's path) of how he or she got the puzzle solved. This puzzle is the 15 Puzzle; but we have it to change by the user's input on what size they want to play (3x3 to 5x5). How to save the board state of each user input, then print those out in order from beginning to solved puzzle state. Subsequently, I would also need transferring the board state to change with using a vector to store the size based on user input. How to proceed, using a first search to solve the puzzle from the current board's state.

calculations.h

Code:
/*Calculations set as a header to keep compiling simple and faster*/

#ifndef calculations
#define calculations
int solved[5][5];
void initialize(int board[][5], int);
void slide(int board[][5],int move,int);
bool isBoardSolved(int board[][5],int);

[Code] .....

View 6 Replies View Related

Visual C++ :: Find Correct Font (height) For Text?

Mar 20, 2014

my problem:I have a text (singleline) and a fix width for the whole text.

How do I find the correct font (height) for this text?

View 8 Replies View Related

C/C++ :: Keeping List Of User Guesses And Output Message If Guess Is Duplicate

Apr 19, 2015

The label "You already picked that" doesn't always appear. Sometimes it does, but only if a duplicate has been entered at least 3 times. I haven't been able to correct this. I am new to programming and array-based lists.

//Objective: randomly generate an integer between 1 and 100, input user guess as to what number it is, and output "correct!" if user guess is the random number, or output "Too high" if the user guess is too high, or output "too low" if the user guess is too low, "you already entered __" if a duplicate is entered and allow the user to keep guessing until they guess the correct number

//libraries
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <iostream>
using namespace std;
struct Guess {

[Code] ....

View 9 Replies View Related

C# :: Save Selected Text From A Popup

Apr 17, 2014

I want to select text entered in a popup and save it. I have a form that contains a text area and a button

<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Height="103px" Width="262px"></asp:TextBox>
<br />
<br />
<asp:button runat="server" text="Add" onclick="Unnamed1_Click" />

when we click on a line in text area I want to open a popup having all text from that line. I should be able to select some of its text then if I click on save button of popup then only selected text should be saved and displayed in original text area of form. I want to use this for multiple sentences of text area.

Add button will add new line.

View 8 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++ :: How To Make A Game Map In Console Using Text

Oct 25, 2014

How would I make a game map in the console using text? The map is to be changed on a turn-based system. I've been thinking about using arrays.

View 1 Replies View Related

C :: File Could Not Be Opened While Filename Seems Correct

Feb 10, 2013

I'm new to C and encountered a weird problem. Here's the code:

int main(){
char name[]="";
readname(name) ;
printf("The filename is: %s
",name);
printf(name);

[Code] ....

I compile this with no problem, but gives "File could not be opened". the strcmp tells me name and "snazzyjazz.txt" are not equal. but when I print them I get the same output.

View 2 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++ :: How To Create Text Based Game Running On Console

Mar 12, 2013

I want to create a text-based game with C++, running on the console. I have made some other text-based console games.

Which is the most interesting text-based game to learn how to program for beginners?

View 2 Replies View Related

C++ :: Text Based RPG Game - Saving Integers And Strings

Jul 14, 2013

I am working on a text-based RPG game and I want to allow the player to save his progress. So I need to save several integers and a string. And my problem starts here "How can I save integers and load them?". I read the tutorial but I dont understand. I need to write a function to save game?

View 8 Replies View Related

C/C++ :: Text Based Game - Adding Players Names?

Mar 28, 2015

I am trying to make a very simple text based game and I want the players to be able to name their characters. Thus, I am trying to have the game ask "how many players will be playing:" and then taking that number (X) and create a place to store that information. I'm trying to get the game to ask, "What is the name of Player1?" Then once the user enters the name it would ask "What is the name of Player2" and that cycle would continue until PlayerX has entered their name. Is what I am doing close?

Here are the errors:

error C2143: syntax error : missing ';' before 'string'(ln 29 col 1)
Error2error C2678: binary '<<' : no operator found which takes a left-hand operand of type 'std::basic_istream<char,std::char_traits<char>>' (or there is no acceptable conversion) (ln 30 col 1)

int NumberOfPlayers;
if (Response1 == "Yes") {
cout << "
How many players will be joining us on our adventure: ";

[Code].....

View 9 Replies View Related







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