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
ADVERTISEMENT
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
Jun 19, 2014
I am working with a new text adventure. The way i want to construct it is by having a class for all living things. in the class you have basic things as: health, gold, vector for inventory holding "struct item". etc...
There is also a class called world, wich navigates through the world.
World class contains of: player location, and a map containing info about the room etc...
Here comes the problem. I want there to be characters to be placed out in different maps, so basically i want the world class to hold objects from Character.
How to do it. In world class i made a map...
std::map<int,"content">
content is a struct i made above in world class:
struct content{
std::string name; // location name
std::string info; // info about location
std::vector<Character>characters;
std::vector<item>items;
};
To sum it up, i have a std::map<int,content>map the int stands for location id. Content holds more info about the room and what's in it
btw the classes are in different files and that means i have to include "Character.h" in the world file so i can set up the vector of characters.
View 2 Replies
View Related
Aug 4, 2013
okay so this program is basically getting the files from user input then reading the original file and convert the string into a uppercase/lowercase form and save it into another file. Is there a way to save the string from the first file to a variable then convertin the string in the variable and copy that onto the new file? So far i have
Code:
#include <stdio.h>
#include <string.h>
int main() {
[Code].....
View 1 Replies
View Related
Apr 19, 2013
I am new to coding Here is the problem. Have a program prompt the user for a filename to open. Change every alphabetic character in the file to a capital letter. Numbers and special characters should not be changed. Print the output to the screen.
Here is my code so far but i am only returning the last line of text capitalized from the file. I am trying to get the program to display all of the three lines of text from the file capitalized. The program displays the file correctly before i try and convert everything toupper();
Code:
Code: #include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
int main()
{
char line[81], filename[21];
int i;
FILE *inFile;
[Code]...
View 6 Replies
View Related
Oct 1, 2014
how to convert a string containing Uppercase/Lowercase/Whitespace/Special Characters to only Lowercase and removing the whitespace and characters.
For example, a message like:
"The: sky is (blue), the wAter is also blue'."
Change that message to:
"theskyisbluethewaterisalsoblue"
View 6 Replies
View Related
Dec 3, 2014
write a program that prompts the user to input a string and outputs the string in uppercase letters. (Use a character array to store the string.) Does this follow the criteria? This program is very similar to one I found on these forums but I have one problem, it outputs everything backwards! EX: dogs will output to SGOD. What I need to do to make it output correctly, I think it may have to do with getline?
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
int main() {
char let[100];
cout << "Enter what you would like to be UPPERCASE: ";
[Code] ....
View 2 Replies
View Related
Jan 3, 2013
From my tests I found the problem to be somewhere in the Mantissa part that converts it to binary.
bool xsDLL GetHexFromSF_IEEE754( void* to, Text from, ui08 tSize ) {
from.UpperCase();
int db = 0, dB = 0, dBEnd = tSize, dBLast = ( tSize - 1u ), dbEnd = dBEnd * 8;
ui08 *data = reinterpret_cast< ui08* >( to );
for ( ; dB >= 0; --dB )
data[ dB ] = 0u;
[Code] ....
Adjustments made, still having problems though. After finding a more useful resource [URL] ..... I got the function looking more like it should but am still having problems...
View 1 Replies
View Related
Jul 25, 2012
Take a number that is entered by a user and turn that into printed text. Ex. 85 would be eight five. The problem I am having is I'm not quite sure how to go about this. I don't know if I should use an array, string, or something else.
View 12 Replies
View Related
Feb 8, 2015
I am writing a program that asks the user for their gender. I know that atoi converts arrays into integers, but I need the input from the user in the form of F or M into a char, and return it to the main function to be displayed at the end of the program.
string Employee::getgender(char gen)
{
cout << "Please enter your Gender: " << endl;
//atoi function would go here, what for char?
getline(cin,gen)
return gen;
}
View 1 Replies
View Related
Sep 19, 2014
Originally I had to create a simple integer palindrome program that looped while the user entered 5 digit inputs (entering -1 stopped the loop). I did this using a conversion to string, reading the length to determine if the length was valid, and then reading the string forward and backwards inside of a while loop. (snippet below)
while( digitsEntered != -1)//Allow user to quit by entering -1 to end the loop
{
ostringstream convert;//conversion stream
convert << digitsEntered;//converted text from number goes in the stream
convertedString = convert.str();//store the resulting conversion to convertedString
[Code] ....
The next stage of this program was to do the same thing with strings instead of integers. However, the option to end the loop by entering -1 is still a requirement.
I think the way to do this is to first determining whether the input is a string or an integer, and if it is a string then read it and if it's an integer determine if it's -1. However, whenever I write code to do this, it converts strings to 0 so the string is not stored and cannot be read to determine if it is a palindrome. Is there a way to determine the type of input without converting it into a different type i.e. read string and then keep string or read number and keep number?
View 3 Replies
View Related
Feb 3, 2015
know of a handy function (or library) for converting between different text formats? I've heard of a library called iconv but I've no familiarity with it. However, it looks promising (from what little I can find out about it...)
Specifically, the text %20 is often used in hypertext to indicate a space character - so the string "Hello There" would get changed into "Hello%20There". How can I easily change between one and the other?
Obviously I could use string replacement functions but that'd need me to anticipate every potential hypertext code sequence.
View 5 Replies
View Related
Apr 22, 2014
I am writing a code in a class that will change the user input which is integer to a string. For example if the user enter 13347..the output should change to "one three three four seven" on the user screen.I'm not getting the right output.
Code below:
#include <iostream>
#include <string>
using namespace std;
string arr[]={"one","two","three","four","five","six","seven","eight","nine"};
class convertTo{
public:
int signed num;
int convet(){
cout<<"Enter a number to convert to string "; cin>>num;
[code]....
View 2 Replies
View Related
Apr 22, 2014
I am writing a code in a class that will change the user input which is integer to a string. For example if the user enter 13347..the output should change to "one three three four seven" on the user screen.I'm not getting the right output.
Code below.
#include <iostream>
#include <string>
using namespace std;
string arr[]={"one","two","three","four","five","six","seven","eight","nine"};
class convertTo{
public:
int signed num;
[Code] ....
View 5 Replies
View Related
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
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
View Related
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
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
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
Mar 19, 2013
I have started making a text adventure game.
if (Choice == 2) {
cout << "" << endl << "You follow the light to the end of the hallway, you find your self in a room" << endl
<< "with natural light coming from a hole in the ceiling." << endl << "" << endl << "You hear the door you just came through, slam behind you!" << endl << "" << endl
<< "There are three possible directions." << endl << "" << endl << "Do you:" << endl << "" << endl << "1) Go forward" << endl << "" << endl << "2) Go left" << endl
[Code] .....
Ignore the if (Choice == 2) at the beginning, that's linked to some previous code.
I want to make the player go back to the first bit of text but i'm not sure how to do this if they keep choosing to go back and forth from one location.
I first thought of doing it by just putting the text back in after they have chosen the option, but I can't do this infinite times.
View 5 Replies
View Related
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
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 12, 2013
int main()
{
string line;
int i,ch;
[Code].....
View 1 Replies
View Related
Mar 21, 2012
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream wormfile("worm.txt");
ofstream dtfile("dt.txt");
[Code] ....
worm.txt has
Code:
I like pie
I like rice
and I like applesauce
while dt.txt has nothing
I was able to get the lines in worm.txt and get it to copy the lines to dt.txt BUT it looks like I can do this in some kind of if statement or while loop. The reason why I don't like to do it the way its in the code because I could have another file that has the lines that I don't know and the code comparing them would take less time then me looking at the file, counting the lines and putting x lines of getline functions in the code.
View 2 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