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


ADVERTISEMENT

C++ :: Value Assigned To Variables X And Y Via Cin - Undeclared Identifier

Aug 28, 2012

I've assigned value to variables x and y via cin, but when I try to compile it, I'm getting:

"1>c:users
isedocumentsvisual studio 2010projects ryityourself ryityourself ryityourself.cpp(26): error C2065: 'x' : undeclared identifier
1>c:users

[Code] .....

Code:
#include "stdafx.h"
#include <iostream>
void enterfirst() {
using namespace std;
int x;

[Code] .....

View 5 Replies View Related

C :: Parse Error / What Value Does Get Assigned

Dec 10, 2013

I get the following parsing error for the code

Code:

#include <stdio.h>

int main()
{
int i=3,4;
printf("%d",i);
return 0;
}

what is wrong with the code? I have put initialize value as 3,4 just to understand what value does i gets assigned.

View 5 Replies View Related

C++ :: Does Int Vars Automatically Get Assigned (0)

Feb 13, 2015

I am wondering if integers and unsigned integers automatically assigned to zero (0) upon declaration like so:

bool randomFunction() {
int i;
if (i == 0) {
return true; //Will most modern compilers return true here?
} else {
return false;
}
}

I am just curious as I have always initialized my ints/unsigned ints variables. Would save me a lot of typing if I didn't have to do this all of the time.

I know that floats and doubles you still have to initialize.

View 4 Replies View Related

C++ :: Variable Assigned Wrong Value?

Nov 15, 2012

Consider the following:

Code:
float foo( float const *bar )
)
{
float temp;
temp = *bar;
...
}

Something I am noticing is that temp right after the assignment to *bar, is not the same value as *bar. This is for a project at work and the code runs on an embedded board with an ARM processor. I've copied the function into a standalone program for both Visual Studio and Code::Blocks and it works correctly there.

View 12 Replies View Related

C++ :: Getchar - Return Assigned Value

Nov 9, 2012

Once again i hit a very simple problem i am unable to resolve. I using Visual Studio 2010, but am compiling for C.

This:

Code:
char i=45;
while(i=getchar() != EOF)
{

should imo work perfectly (yes, no real code, just to demonstrate the issue), but it doesnt. Getchar() always returns 0x01. Why is that? This, in contrast, works perfectly fine:

Code:
char i=45;
while(i!= EOF)
{
i=getchar();

Shouldnt an assignment always return the assigned value?

View 2 Replies View Related

C++ :: OpenMP - Intervals Assigned To Threads?

Feb 6, 2014

Is there a way of knowing which indices a thread is assigned in a parallel openMP scope?

View 6 Replies View Related

C/C++ :: Passing Var Assigned In A Class File To Functions Outside Of Int Main?

Dec 7, 2014

I'm trying to pass the value of an object created from a class file to a function outside of the "Int Main" function in the main.cpp file. I've successfully created the object, I just want to pass it to a void function but I'm getting the scope error below. I'm not sure how to correct. I'm not having much luck with research either (static variables?).

error: 'TicTacToe' was not declared in this scope

main.cpp
#include <iostream>
#include <cstdlib>
#include "Signature.h"
#include "Gameplay.h"
using namespace std;
// Initialize array
char square[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

[code]....

View 4 Replies View Related

Visual C++ :: Access Violation Reading Void Assigned Dynamically Allocated Value Inside Function

Sep 16, 2013

Why the void pointer passed to testb doesn't continue pointing to the allocated integer after the function call returns.

Code:
#include <stdio.h>
#include <iostream>
void* testa() {
return new int(1);

[Code] ....

View 5 Replies View Related

C++ :: Can Object Of A Class Be Assigned To Another Of Different Class?

Nov 9, 2013

I fully understand that a variable of one simple data type cannot be assigned to another of a different data type in an assignment statement, except when type-conversion(i.e. casting) is employed. For structured data types (like classes), I know that the assignment operator can be overloaded; but this only addresses objects of the same type.

My problem is that I have read data from an input file into an object of one class, but I want to transfer the contents into an object of a different class in an assignment statement. Can this be realized given that the two operands of the assignment operator (=), in this case, would be of two different types?

View 5 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++ :: 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++ :: 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 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

C++ :: Accessing Variables From Other Files

Sep 26, 2014

I don't have in depth code or anything. I tried this but can't seem to wrap my head around it.

Code: //header.h
namespace test {
int arr[5];

[Code] ....

Also tried putting int arr[5] in a Test class within test.h.

I have 2 structs in another file, the main, and want to make an instance of the arr variable, in a separate header, for each.

View 2 Replies View Related

C++ :: Uninitialized Variables In Structure

Aug 7, 2013

I have a structure

Code: struct time{
char hours;
char minutes;
char seconds;
char dummy;
};

I have kept dummy as the data to be aligned.I will update hours, minutes, and seconds , but will not use dummy in any case.

If I don't initialize 'dummy' does it make any errors ?

Do I need to initialize hours, minutes, seconds as well before I use the structure ?

If so is there any particular reason ?

View 6 Replies View Related

C++ :: Initializing Variables In Each Class

Sep 26, 2014

I am working on a homework assignment and have most of the program working, but when I try to compile it keeps telling me to initialize the coin variables in each class. However, they are supposed to be added then removed so I don't want to set them back to zero.

Rewrite the Purse program given in Page 35 with functions to perform insert and remove operations. The function insert (int p, int n, int d, int q) will initialize pennies, nickels, dimes and quarters. The function dollars() will return the dollars. The function remove (int p, int n, int d, int q) will subtract pennies, nickels, dimes and quarters. The function display() returns a new String to print the content of the purse with remaining pennies, nickels, dimes and quarters.

Code:
usingnamespace std;
int insert_money (int *p, int *n, int *d, int *q);
int remove_money (int *p, int *n, int *d, int *q);
int dollars();
int main()

[Code] ....

View 2 Replies View Related

C++ :: Vector - Out Of Scope Variables

Dec 14, 2013

The situation is the following :

Code:
vector<int>& function(int a , int b){
vector<int> s(3000000);
vector<int> xxx(4);
return xxx
}

Not to board people with details but if i am returning the the reference to a vector xxx what happens to vector s. is it destroyed ?? it should be, but i don't see it on my memory map (memory is not released) . can this be or should i go and search for error on some other place.....

View 2 Replies View Related

C :: Returning Value For Item To Variables?

Mar 4, 2014

What the code below is not doing is returning a value for item to my variables (item1, item2, etc..) I'm not sure how I can make a function prototype that will ask for input and basically recycle after going through the program to a new value for each item. I also need to input individual tax for each item. I will also post it in this message:

double tax, item,salesTax;
double cost(double);
double CalcSalesTax(double);
main(){
double total,item1, item2, item3, item4, item5, tax1, tax2, tax3,tax4,tax5;

[Code].....

View 13 Replies View Related

C :: How To Enable Numeric Variables

May 22, 2013

working on this code I have encountered a few issues. My program lists the occurrence of each letter but i'm unsure of how to enable numeric variables. how to improve the overall quality of the code.

Code:

#include <stdio.h>
#include <string.h>
int main()
{
char string[100], ch;
int c = 0, count[26] = {0};
printf("Enter a string

[Code]...

View 4 Replies View Related







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