C++ :: Creating Inventory - Array With More Than 1 String?
Jul 14, 2014
How would i do this? Im trying to create an inventory but this just will not work, when i do it how i have it originally (as shown below):
cout << "Do you have weapons and armor?: ";
cin >> yEquip;
if (yEquip == 'y') {
cout << endl;
string invintory2[6] =
[Code] ....
the program outputs this:
cout << "Do you have weapons and armor?: ";
cin >> yEquip;
if (yEquip == 'y'){
cout << endl;
string invintory1[6];
[Code] ....
however programing it like this seems very... time consuming.
my other arrays (normal ones that just hold a set of int's) look like this:
int *player[] = {&yhp,&ymp,&ypatk,&ymatk,&yratk,&ypdef,&ymdef,&yrdef,&ydb,&yacc,&ycr,&yas};
Is there any way to do a string array in this way?
View 8 Replies
ADVERTISEMENT
Jan 26, 2013
How to make a program in C to create a product inventory file containing pro0duct name, cost and quantity and then read the prouct inventory file.
View 9 Replies
View Related
Apr 24, 2013
Creating a C program that can pick words in a string or array and save it in different location, later combine everything in one string or array. It will be using simple programming C code. For example (arrays, pointer) but not interrupts or other string functions.
In a sentence like this:
Size= 70
$--GSV,x,x,x,x,x,x,x,...*hh $--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,b,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh $--GLC,xxxx,x.x,a,x.x,a,x.x,a.x,x,a,x.x,a,x.x,a*hh $--GSA,a,a,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x.x,x.x,x.x*hh
The program must capture the $--GGA string then extract from this string:
1) hhmmss.ss
2) IIII.II
3) a (if a = to N or S replace N or S with + or - respectively )
4) yyyyy.yy 5) b (if b = to E or W replace E or W with + or - respectively )
Save them in an array and display as well. After all the saving, the program should combine them to one string. That the final output.
View 7 Replies
View Related
Feb 9, 2013
I made two dimensional array to represent my (game) inventory. Slot is empty if its value is 0 and 1 if not.
Now i need to find if i can put new item in my inventory that can take up 4x2 slots. I tried this but it doesn't work as i expected:
#include <iostream>
int main() {
const int inventorySlotRows = 5;
const int inventorySlotColumns = 5;
int arr[inventorySlotRows][inventorySlotColumns] =
[Code] .....
View 2 Replies
View Related
Mar 27, 2014
So I'm writing an RPG and I'm in need of an inventory system. Of course as an relatively old member of the forum I know best than just come here and ask so I've already researched quite a bit and I've formulated this idea.
I've kind of conceptualized it like so: I'll have some sort of STL container of a unique_ptr of my base item class. There will be derived item classes. Taking advantage of polymorphism I can then call the new Derivedclass when inserting it in the STL container.
My questions are: What STL container should be used for the inventory(fixed sized)?
View 2 Replies
View Related
Mar 6, 2015
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
char * form(char *format, ...);
}
[code]...
So, this is the code i have problem with, as far as i can see, function form actually does the same thing that printf does.It probably puts all of the arguments sent to the function together into one string.
View 4 Replies
View Related
Jan 15, 2015
im working on mine first 2d game and im practicing a lot, how to input my inventory for character ( for items, and others ) So, i just want to let u know that i have :
#define WEAPON_LONGSWORD (1)
#define WEAPON_WARAXE (2)
#define WEAPON_DAGGER (3)
#define WEAPON_SHORTSWORD (4)
#define WEAPON_BOW (5)
#define WEAPON_MAX (6)
So, i want to put this in my shop and if i buy it i want to appear in my inventory, or sell sell trought my inventory.Also i have one define
#define WEAPONBEGIN_WOODENSTICK (1)
Which will go instant ( when u create character ) to inventory. And:If i have 1, 2, 3, 4, 5, 6, 7, 8, 9 slots ( example ) and i sell item which was on 3rd slot, what will happen with others ? will they just go back for one slot or ?
View 5 Replies
View Related
Sep 2, 2014
I am making a text based rpg for school and im having troubles with it. Ineed to add an inventory into my game and im not to sure as to where or how.. this is what i got for player
#ifndef PLAYER_H
#define PLAYER_H
//console Util.h includes <iostream> , <string> and <window.h> and defines
//the NOMINMAX macro. As a result of including ConsoleUtil.h, PLayer will
// also knaow about thoes objects.
#include "ConsoleUtil.h"
[Code] ...
View 2 Replies
View Related
May 12, 2013
I have defined a class in a header file; just the class, no templates involved. I have a program where I'm reading in data in string format. Each string consists of a word, a delimiter, and a variable name. Example:
cajun/mustard
I want to take that string and make it the variable name of that class type. It would be implemented along the lines of:
Code:
string str;
//read/process string here, get:
str = "mustard";
createName(str);
//pass string to creator function When the function is called, I should get the variable:
Class mustard;
Thing is, I'm not supposed to know beforehand what the variable names are, only that I create them as they are read in. It could be mustard, it could be Maynard_James_Keenan, it could even be bazinga.
My problem is, what do I do for createName()? I've looked into the concepts of pairing, Factory implementation, and maps, but I don't think they answer my question.
(P.S. if I run into the same variable name being read in twice, what steps can I take to make sure that a duplicate variable isn't created? Do I need to add in code, or does the compiler know to watch for multiple variables of the same name?)
View 6 Replies
View Related
Feb 22, 2014
I can't get c++ compilers to create or open files with a string input, even though the compiler accepts a file name in "quotes". How can I get this compiled (I am downloading a series of file names which I need to load into a consolidated file).
My coding (the commented line works, the string example does not).
//indirect file open example
#include <iostream>
#include <fstream>
#include <string>
[Code].....
View 4 Replies
View Related
Aug 13, 2014
I need a function to return a string
I need to pass input as "a,b,c,a,c,d,e"
function should return out put as
"a,b,c,d,e"
View 2 Replies
View Related
Aug 15, 2014
I am making a program that formats a string. I want to create a new 2 dimensional string that will have many other chars and strings in it beside the original string. Then I split the string up on the newlines and return it. Adding different parts to the 2d string e.g. I need to add five _ as chars not string then I need to add different things. First I use sprintf () to add as much as possible. And then I do what to add the rest?
View 13 Replies
View Related
Jan 13, 2015
I'm trying to create an inventory system in C++ using classes and objects. Here is what I have now
Item.h
#pragma once
#include <iostream>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
[Code]....
Basically what I want my inventory system to become is this: [URL] Each slot can hold an item.
Basically this inventory system should be able to do what RS Inventory system can do. (Hold items, Use items, Equip Items (No need for moving item))
View 5 Replies
View Related
Mar 5, 2014
I need to convert the bit representation of an unsigned char into a string.
so like 254 would be "11111111"
I'm having some trouble where no matter what number I try to convert I get 01111111.
string bin2string(unsigned char N) {
string sN(8,'0');
unsigned char X;
unsigned char Y = 0;
for(int i = 0; i < 8; i++){
[Code] ....
View 4 Replies
View Related
Jun 7, 2013
So my inventory program runs fine as far as I can tell. Except when entering "Amounts" with more that 1-precision . ie
Amount Entered : 25.99 // Problem
Amount Entered : 25.9 // No Problem
When entering say 25.99, the rest of the file is jibberish. but 25.9, the rest of the file is fine
Code:
#include <stdio.h>
typedef struct toolRecord{
int record_num;
char tool_name[16];
int quantity;
double price;
[Code] .....
View 5 Replies
View Related
Nov 14, 2014
You are requested to create an inventory control application for a drink stall (give a name to the stall). The application is used to show the list of drinks the stall sells, how many of each item on‐hand and the cost of each item. The records are to be saved and retrieved to/from a binary file called “drinks.txt”. For each drink in the stall, your program is to keep the information as a Record Structure called DrinkRecord. The structure should at least consist of the following:
(1) Item Number
(2) Item Name
(3) Quantity
(4) Unit Price
Your application should have the following features:
(a) Display a drink information
(b) Add a new drink information
(c) Update a new drink information
(d) Delete a drink information
(e) Display all drink information
#include <string>
#include <fstream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
[code].....
Everything works fine with minor issues, but I'm having trouble with the editing function. I need to be able to search for a specific drink then be able to edit its contents and print the new contents to the file. I have not created a structure yet. I will do that as soon as possible.
View 1 Replies
View Related
Apr 10, 2015
I am having some trouble creating a listbox in visual studio. I declared an array, set initial values, and now I would like to be able to update those values. It is a pizza inventory app, so I need to update the initial values once the user has added inventory. This is the code I have for the "Update Inventory" button:
// read in value and convert to double
double dblInput = Convert.ToDouble(txtInput.Text);
// loop through ingredients and add inventory to selected ingredient
for (int i = 0; i < dblInventory.Length; i++) {
// is item at i checked for update?
if(lstInventory.GetItemCheckState(i) == CheckState.Checked)
[Code]....
View 11 Replies
View Related
Sep 18, 2012
I am working on an assignment to create a Complex number calculator. In this assignment I am to ask the user for input to the calculator. We are given a sample run output that looks like this.
Enter operand1: 3 4
operand1: (3, 4)
Enter operation : +
Enter operand2: 1 2
(3, 4) + (1, 2) = (4, 6)
My question is how would I take from the user: an integer followed by a space followed by another integer and convert that into two seperate accessible int values that I can save as real and imaginary values.
View 4 Replies
View Related
Aug 25, 2014
You are required to write a program for a Used Car Dealer company. In the system you need to maintain the cars’ inventory and details. Each car in the company contains the following details:
• Car Registration Number
• Car Make or Brand
• Car Model
• Car Colour (eg. Silver, Black , Red)
• Year of manufacturing (The year the car was manufacture)
• Engine Capacity (in cc)
• Transmission (manual or automatic)
• Cost of the car (SGD)
The Car Registration Number is in the format of AAA1234 or AA1234A or A1234A which is accordance to the Malaysia car registration format. The A alphabet is in accordance to the registration number for respective in Singapore. (eg. AEW9829 or W1212Y or MCD1177). Note the A and the 1234 total count in the registration number can be less than 3 like AT9829 or BHY280. The Car Make is for the identifying the manufacturer of the car like Honda, Toyota, Proton..etc. The Car Model is to represent the Manufacturers’ respective model like Honda City, Honda Civic, Honda Accord, Toyota Vios, Toyota Camry … etc.
You are required to create menu and operations for:
1) Create a new Car account
2) Edit existing Car account details
3) Remove a car account from the system
4) Search for cars in the system (based on Car Make, Model, Year of manufacturing or Price)
5) Check total inventory in the system
View 1 Replies
View Related
Feb 23, 2014
Write a constructor that initializes a new inventory object with the values passed as arguments, but which also includes a reasonable default value for each parameter.
#include "stdafx.h"
#include <iostream.h>
#include <stdio.h>
#include <string.h>
class inventory {
[Code] ....
I am not trying to get my homewotk done, just to understand my errors. It complies without problem. But doesn't run.
View 2 Replies
View Related
Mar 7, 2013
Here is the code:
// Creating and joining string objects
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::getline;
// List names and ages
void listnames(string names[], string ages[], size_t count) {
[Code] ....
I may be wrong, but the problem seems to be in the function "listnames". Specifically, the output statement inside the while loop. I don't understand , how the ++ operator is behaving in this statement. The output produced does not match what's printed in the book. I usually just type all the examples, but with this one I also downloaded the source code from the book's website to make sure the error wasn't due to mistyping.
View 4 Replies
View Related
Oct 10, 2012
How could I create an array that would in PHP look like this:
PHP Code:
$something['argument1']['argument2'] = "some data to store";
View 14 Replies
View Related
Oct 17, 2014
I've been given specific instructions to create an array inside a Class Matrix using a constant n. This is my class but I am getting errors. I thought that maybe I had to initialize the const and the array using the constructor function Matrix() instead of directly in the class, but I didn't have any luck with that either.
class Matrix
{
public:
Matrix();
private:
const int n=3;
int e[n][n];
};
View 4 Replies
View Related
Sep 13, 2013
How would one go about creating an array that cycles through the same numbers?
For example {0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,etc} for a chosen length?
View 2 Replies
View Related
Nov 4, 2013
Im supposed to create an to array of eight Circle objects initialized with the following radii: 2.5, 4.0, 1.0, 3.0, 6.0, 5.5, 3.5, 2.0. Then use a bubble sort to arrange the objects in ascending order of radius size before displaying the area of each object.
The error I get is "Cannot open include file: 'Circle.h': No such file or directory". Do I have to create a separate file for it?
#include <iostream>
#include <iomanip>
#include "Circle.h"
using namespace std;
class Circle {
public:
Circle()
[Code] ...
View 1 Replies
View Related
May 29, 2014
I am trying to create n number of files (n being an integer), by passing the name through a character array (and obviously changing its value at each iteration). But the problem is that the program compiles and executes but not a single file is created.
Here is my code snippet.
void file_phipsi(int m)
{
int a=0,n=0;
char *str1;
[Code].....
View 4 Replies
View Related