C/C++ :: Cannot Use CPP File Of Variables?

Mar 9, 2014

For a few days now I have been trying to call variables (globes) from another CPP file so I can add/subtract data from them and use them in other places. I have my defines.h file working which contains all my constants but my defines.cpp (which is required to hold all the non constants) are not. Anyways I am getting the error :

Error1error LNK2001: unresolved external symbol "float MONEY" (?MONEY@@3MA)C:UsersJacksdocumentsvisual studio 2012ProjectsAssignmnet2Assignmnet2main.objAssignmnet2

My defines.cpp

//#include "Defines.h"
using namespace std;
//Game mechanic variables
extern float STOCK_LEMONS;
extern float STOCK_SUGAR;
extern float STOCK_ICE;

[Code] .....

If I were to un-comment the "float money = 50" it would work...

I also didn't include my defines.cpp into my defines.h as I got to many errors...

View 2 Replies


ADVERTISEMENT

C++ :: Read Variables From File

May 12, 2013

I want my program to read variables from file "input.txt":

Please choose the crystal lattice. Type 1 for BCC, 2 for FCC, and 3 for HCP: 2
Please enter lattice parameter (a): 1
For HCP please enter second lattice parameter (c): 1
Please enter the number of translated cells along X axis: 2
Please enter the number of translated cells along Y axis: 2
Please enter the number of translated cells along Z axis: 2

Moreover, I want program to read only the numbers after colon. How can I do it?

Code:
#include <iostream>#include <fstream> // to read from file
using namespace std;
int main () {
int latticeType;
int dimX, dimY, dimZ; // number of translated cells along each axis
float d; // lattice parameter

[Code] ....

View 2 Replies View Related

C :: Set Variables Based On File Read?

Dec 9, 2013

I am trying to fscanf a file and need to read the variable name 'f9' and 'a2' for example in the sample below and get their corresponding values '8' and '2' and then in my C program set the variables f9 and a2 accordingly (which I can declare as variables). Is this possible?

I making a Sudoku Solver and am thinking I would store the puzzle solution in a 2D array with a1=0, a2=1, etc... where 0, 1 are the array indices... then just print the array as the solution.

Note: The a1, a2, a3, etc... is my own numbering of the indices where the letter corresponds to the row and the number corresponds to the column (starting from 1) which I use when feeding to the solver.

I have a file that has the following format (output of Z3 SMT solver):

sat
(model
(define-fun f9 () Int
8)
(define-fun a2 () Int
2)
(define-fun c5 () Int
6)
)

View 1 Replies View Related

C++ ::  modifying Several Variables Via Header File

Feb 18, 2014

I'm trying to split up my game (about 1300 lines) into header files, but I'm coming up with a problem whenever I try and put a function in a header file, when that function was modifying some variables that were defined before int main in the .cpp. For example:

int variable1 (0);
int variable2 (0);
void increasevariables() {
variable 1 = variable1 + 1;
variable2 = variable2 + 1;

[code].....

If it only modified one variable then I could just pass that variable and the return it:(return variable1 + 1;)But I don't know how to make a function in a header file modify several pre-existing variables. In the actual program, the variables are dependant on each other and the modifying is a lot more complicated, so I'd rather not split it into several functions and run one at a time if there's another way.

View 4 Replies View Related

C++ :: How Come Header Variables Are Not Recognized In Its CPP File

Feb 24, 2014

I declared 3 private variables in header file.

I try to access one of the variable in its corresponding cpp file but I get an error message saying it's undefined. I did #include the header file. Why is this?

View 4 Replies View Related

C++ :: Retrieving Variables From Text File

Apr 18, 2013

I have a text file config.txt which has:

"red = true"
"blue = false"
"children = 10"

I want to write a code that reads the values of these variables red, blue and children when executing the code.

I have something like this:

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main () {
ifstream Configure;

[Code] .....

I want to read the read the values of red, blue and children in and use them when the program executes.

View 1 Replies View Related

C++ :: Reading Variables From Data File

Feb 18, 2014

I can't get my program to read the rest of my variables from my data file it will only read the first two and my end of file won't work it keeps continuing on.

879.46
C 400.00
D 100.0
F 525.00
C 450.00
D 500.00
D 1000.00
C 2000.00
D 3000.00
D 3500.00
C 5500.00
C 500.00
B 200.00
C -235.00
D 250.00
H -500.00
D 500.00
E

That's my data it will only read the inital number and C and D but nothing else.

// develop algorithm to balance checking account make transactions

#include<iostream> // required for keyboard and screen I/O
#include<fstream> // required for external file stream
#include<iomanip>
#include<conio.h>
#include<string>

[Code] ......

View 5 Replies View Related

C/C++ :: Reading CSV File And Storing In Variables

Mar 16, 2015

how to read a csv file where the data is seperated with commas so the csv file looks like:

programming,03,60,141,01,W,2015
programming,03,60,141,30,W,2015
Algebra,03,62,102,02,S,2013
Religion,08,98,938,20,F,2014

So i need the name of the course in one variable, the course code (ex 0360-141-01 for line 1) in another variable and the term (ie W2015 for line1). So i got the name done but cant figure out the course code since i need more than one value that is seperated by a comma. my code is:

#include<stdio.h>
#include<string.h>
typedef struct CourseInfo {
int courseID;

[Code].....

View 2 Replies View Related

C# :: Saving Variables To Text File

Jan 26, 2015

I started with C# 2 days ago, but i have made 3 "games". Its something like Cookie Clicker, very simple and very easy.

But I have problem with saving the game. I want to save values of variables to text file when i click on button, and when i click on another button i want to values of variables load. Just simple save system. How it works and so.

View 8 Replies View Related

C++ :: Create Header File In Which Can Change Value Of Variables

Apr 12, 2013

I just can't seem to find how to create a header file and where I can change the value of the variables. It sounds simple.

View 12 Replies View Related

C++ :: Declare Static Variables In Header File

Oct 15, 2013

I read in another forum that it is bad practice to declare static variables in a header file? Is that true and if so why.

View 1 Replies View Related

C :: Maintain List Of Variables Inside Source File

Apr 24, 2013

I'm about to begin work on an exercise that requires me to maintain a list of the variables inside a c source file. I'm trying to figure out how I'm going to pluck out the variable names from all the other noise. My first thought would be to count any word that isn't a keyword or other type of grammar syntax, such as parenthesis, brackets, semicolons, etc. right?

View 10 Replies View Related

C++ :: Read From A File And Store Information In Separate Variables?

Dec 8, 2014

So I have to read from a file, and store the information in separate variables. My problem is that for some of the information I need multiple words, and for others I don't, so I cant simply store 1 word into a variable and store the next in another in so on. To demonstrate what I mean let me give an example.

Dog Cat Blue Bird Snake White Horse

I am able to store "Dog","Cat","Blue","Bird"...etc in variables but I don't know how to make it so I can store "Dog" in one variable, "Cat" in a second variable. and "Blue Bird" in a third variable. "Snake" would be the 4th and "White Horse" would be the fifth. How can I read a file and manipulate the pointer to grab what I need?

View 2 Replies View Related

C++ :: Header File That Is Continuously Updating To Extract Certain Variables?

Mar 10, 2013

I need to write a C++ program, that extracts certain variables, x y z, from a file that is continuously being updated x y z. These variables are going to be used to recalculate a new answer.

My question is to see if it is possible to have an include .h file that is always being updated so that I can extract these three variables from it, and always have the newest venison of each variable, so that the answer to the equation is always the newest updated. Should I use fopen or fwrite to do this.

View 4 Replies View Related

C++ :: Reading From File And Store Values Of Each Line In Multiple Variables

May 6, 2013

So I have this text file that I am trying to read from and store the values of each line in multiple variables.

Let's say my text file contains

AXSYZ3482 Tom 100 112

and my code below here works fine when the lines in the text file is separated by spaces.

while (fscanf(fp, "%s %s %d %d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}

But let's say my file was to look like this instead.

AXSYZ3482:Tom:100:112

But if i try this below...

while (fscanf(fp, "%s:%s:%d:%d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}

It seem to store the entire line in userID including the ":". I want to ignore the ":"'s and store everything in between in respective varibles in the order specified above.

So first string in userID, then ignore the :, then second string in name, and ignore the next :, and so forth. How I can accomplish this?

View 2 Replies View Related

C++ :: Read In Lines From A File / Store In Variables Then Construct Instances Of Class

Aug 22, 2013

I can't get my code to compile, i need to read in lines from a file and store them in variables. Then i have to construct instances of my class for how many lines there are in the file and take those variables into them.

I'm getting this error :

"a2.cpp:40: error: cannot convert `Employee' to `Employee*' in assignment"

#include<iostream>
#include<string>
#include<fstream>
void displayInfo();
using namespace std;
class Employee{

[Code] .....

View 1 Replies View Related

C++ :: Specifying And Multiplying Two Variables

Feb 23, 2014

I'm very new to C++ so I've been trying to run through some code examples to begin to learn basic structures and syntax, but I've recently run into a problem using examples from the 7th ed. of Sams Teach Yourself C++. I'm using the code provided within one of the examples that allows you to specify and multiply two variables, but when I compile and run the executable the final output seems to only show the first variable and b/c of this the multiplication operation does not work.

Here is a my example code:

Code:
#include <iostream>
using namespace std;
int main() {
cout << "This program will multiply two numbers" << endl;

[Code] ....

View 3 Replies View Related

C++ :: Adding 3 Variables One After The Other

Nov 19, 2013

So here is what i need i need a way i can add 3 variables one after the other example:

int a = 1;
int b = 2;
int c = 3;

//Here comes my problem

int d = a + b + c;

When I write it like thet d = 6 ,
but I need it to be 123,

View 4 Replies View Related

C++ :: How To Skip Variables

Mar 19, 2013

I am just a beginner in c++..I am making a program on a physics formula PV=nRT(this is formula of ideal gas equation)i have build the program and it run excellently but i want to improve this i am using a condition p==0 because i want to find 'p' but the problem is every time i run the program i have to input p=0 in the screen but i want the program to skip "p" ( take automatically "p" as 0 when i press enter and got to another varibles)

#include <iostream>
#include <cmath>
using namespace std;
int main()

[code].....

View 11 Replies View Related

C++ :: How To Initialize Map Variables

Jul 8, 2014

How are map variables initialized?

PLEASE EXPLAIN THE FOLLOWING CODE TO ME?

// accessing mapped values
#include <iostream>
#include <map>
#include <string>
int main () {
std::map<std::string, int> mymap;

[Code]...

View 2 Replies View Related

C++ :: First Derivative With Many Variables?

Jun 19, 2013

I have First derivative function implemented in C++. More details [URL] ...

In programming, I'm dealing with a lot of variables. x, y, z & x', y', z' & x'', y'', z'' These are only for one device. The problem is how can I deal with velocities and accelerations the way I did with positions? This is the code

while (1) {
/* Perform a synchronous call to copy the most current device state.
This synchronous scheduler call ensures that the device state is obtained in a thread-safe manner. */
hdScheduleSynchronous(copyDeviceDataCallback, ¤tData, HD_MIN_SCHEDULER_PRIORITY);

x_Position[2] = currentData.m_devicePosition[0];
x_Position[3] = currentData.m_devicePosition[0];
x_Position[4] = currentData.m_devicePosition[0];

[Code] ....

I've tried to create x_Velocity[5] and

x_Position[2] = currentData.m_devicePosition[0];
x_Position[3] = currentData.m_devicePosition[0];
x_Position[4] = currentData.m_devicePosition[0];

[Code] ....

I'm trying also to store x_Velocity in vector. Every time I deal with whether array or vector, the first two points of x position are affected because I'm calling the function for the velocity.

View 8 Replies View Related

C++ :: Value Assigned To Int Variables?

Feb 6, 2013

Suppose x, y, and z are int variables. What value is assigned to each of these variables after the last statement executes?

x = 4; y = 11;
z = y - 2 * x;
x = z + y;
y = x + 5 * z;
w = x - y + 2 * z;
x = y + w - x;
-w;

View 3 Replies View Related

C++ :: Object Variables Going To NaN

May 26, 2014

So I am trying to develop a sort of 2d spacesim engine for creating games in C++. The project uses SFML for graphics, and I am currently trying to compile it on Linux using g++.

The main issue that I am wrestling with is that of simulation objects having their position, velocity, and rotation variables constantly getting set to NaN for reasons that are beyond me. The behaviour is not consistent, and occasionally will occur or not occur without any discernible pattern.

The github repo for the code is here: [URL] ....

I understand that NaN values can spread easily by operations on one another, but I cant seem to figure out where the initial issue is occurring here.

View 2 Replies View Related

C/C++ :: Use The Same Variables Between Functions?

Mar 6, 2015

I'm trying to use two variables for two different functions.

#include "stdafx.h"
#include <iostream>
#include <cstdlib>

[Code].....

Every time screen2() runs it always outputs "Numbers entered were 0 and 0". I want the numbers that were entered in by the user in screen1() to be displayed.

View 2 Replies View Related

C# :: Can Use Variables From Other Classes

Feb 23, 2014

im creating an address book. One address book contains a ListBox, New User button, Edit User and Remove User button. The first form is suppose to allow you to view the users you've created on the ListBox and you can decide whether you want to remove it, create a new one or simply edit the user. Now The second form simply contains labels and textbox along with a save button. I'm having a bit of issue figuring out the ListBox. I want to be able to create a user and have the user be posted on the ListBox. I read that i must instantiate listbox then simply add it. Now on my form2 i have a for loop that loops through an Array of String were all the users will be created on. How can i call that array of string on to the form1?

Form 1:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

[code].....

EDIT:I just figured out that to call a variable from one form to another you simply instantiate the form then simply call it. PS. must be set to public:

ListBox1 createUser = new ListBox1();
createUser.userString[0];

why doesnt it show the windows when i run without debugging?

View 1 Replies View Related

C/C++ :: Passing By Value With Two Variables

Jun 24, 2014

This is my first time working with C++ and I have put together this program and came up with two errors and I am unsure what it is wanting me to do. The errors I got are:

1>c:usersownerdocumentsvisual studio 2010projectsweek5week5passing_by_value.cpp(30): error C2064: term does not evaluate to a function taking 1 arguments
1>c:usersownerdocumentsvisual studio 2010projectsweek5week5passing_by_value.cpp(38): error C2064: term does not evaluate to a function taking 1 arguments

#include<iostream>
using std::cin;
using std::cout;
using std::endl;

[Code].....

View 6 Replies View Related







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