C++ :: Variables Not Passing Correctly

Mar 10, 2013

Well I have my program running and the Variables are not passing correctly and the return statements are not returning correctly. Here is the parts that are not working.

#include <iostream>
#include "fight.h"
#include <time.h>
#include "player.h"
#include "stdlib.h"
#include <cstdlib>
using namespace std;

combat A;
combat::combat(void)

[Code] ....

View 11 Replies


ADVERTISEMENT

C/C++ :: Sscanf Not Storing Variables Correctly

Jan 23, 2015

I'm trying to read in 3 values from the first line in a file. I want to take those 3 values and store them into 3 variables.

char buffer[100];
if((fgets(buffer, sizeof buffer, in) != NULL))
{
printf("current buffer is %s", buffer);
double tmpPrePrice, tmpDoorPrice;
int tmpTicCount;
int a = sscanf(buffer, "%d %d %d", &tmpPrePrice, &tmpDoorPrice, &tmpTicCount);
printf("applied %d variables %d %d %d", a, tmpPrePrice, tmpDoorPrice, tmpTicCount);
}

The input is

15 25 200

And the result:

current buffer is 15 25 200
applied 3 variables 15 0 25

any reason these aren't being stored properly?

View 3 Replies View Related

C++ :: Passing Lambda As Template Parameter Not Working Correctly

May 30, 2013

I've was trying out a function template to automatically get the type of a lambda, but it seems that it won't compile

I've tried two different ways:

1.
template<class HASHER>
auto make_unordered_map(size_t bucketCount, HASHER const && hf)
-> unordered_map<string const, HASHER>&& {
return unordered_map<string const, int, HASHER>(bucketCount, hf);
} auto x = make_unordered_map(1, [](string const& key)->size_t { return key[0]; });

2.
template<class HASHER>
auto make_unordered_map(size_t bucketCount, HASHER const && hf2)
-> unordered_map<string const, int, decltype(hf2)> {
return unordered_map<string const, int, decltype(hf2)>(bucketCount, hf2);
} auto x = make_unordered_map(1, [](string const& key)->size_t { return key[0]; });

The test code are located here:

1. [URL] ....
2. [URL] ....

They are both based on the code that is stated to work in those examples. I.e.:

auto hf = [](string const& key)->size_t { return key[0]; };
unordered_map<string const, int, decltype(hf)> m (1, hf);

View 13 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 :: Passing Variables Among Functions

Mar 6, 2015

I have this code where I am trying to retrieve the contents of the variable dev1 and dev2. for some reason when i compile and run I am getting 0 and 0.

Code:

typedef struct {
uint32_t x;
uint32_t y;
} sample;
void get_sample(sample *one)

[Code].....

View 9 Replies View Related

C++ :: Passing Variables Into A Function

Mar 29, 2014

ok I have a class Player with lots of variables and im gonna call a function to checkXp, if I call it with the whole player object does it use a lot more memory then if I just passed the couple things I need?

ex
checkXP(Player* play) // this is a whole object of player
or
checkXP(play->getXP(), play->getLVL()) // the variables I want.

I just realized I may not be able to modify anything from player in the checkXP() function

question 1: does passing the whole object use more memory
question 2: if I passed as just the variables I need, I wont be able to modify anything of object play?

View 1 Replies View Related

C++ :: Passing Variables Between Functions

Jan 29, 2013

I need passing some variables between functions. Here is the first part of the code which does work.

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct CarType {
string maker;

[Code] ....

Now the book says to take the following program and add a member function to the CarType class which prints the values of all of its data members. Add two more data members which are relevant for cars. Add the use of these data members to the program (to the assignment statements for MyCar, to the operator prompt and input inside the getYourCar function, and to the print function you have created).

Here is my code. Whenever I run it, it takes my assigned variables in MyCar and prints those instead of the one which the user is inputting.

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
using namespace std;
struct CarType {
string maker;

[Code] .....

View 3 Replies View Related

C++ :: Passing Array Of Variables By Reference?

Sep 10, 2014

I define an integer variable and pass it by reference to a function.

int func(int &x)
{
// do something
}
int x;
func(x);

However, I have not only one variable but an array of variables with its predefined name. How do I pass to the function by using loop? Example:

int x, y, z;
func(x);
func(y);
func(z);

How can I do this by using loop?

View 7 Replies View Related

C++ :: Passing Both Private And Public Variables-functions?

Mar 6, 2015

How to properly pass both private and public variables/functions from one class to another?

View 3 Replies View Related

C++ :: Passing Data Between Threads Without Using Global Variables

Nov 6, 2013

I have a main thread and a worker thread. How do i pass data between them when both are already running without using global variables?

View 1 Replies View Related

C :: Passing Int And Float Variables From Main And Getting Values From Another Function

Feb 3, 2015

I have the main() - which has entries like

Code:

main() {
int ss, ret, z;
float yy;
ret = function1(&yy, &ss, &z);
//int function1(flat *cc, int *dd, int *k) - is it correct?

[Code]...

View 5 Replies View Related

Visual C++ :: Passing DDX Control Variables Between Dialogs (Parent->Child)

Jul 19, 2013

I have a main dialog which has (DDX?) controls for the user. eg a slider, and a combo box.

Previously, an image adjusted by these controls was in the same dialog.

I need to put this image in a New, separate dialog but it still must be controlled by the slider and combo box on the main dialog.

My question is how can I pass the control's variables between the dialogs? I have, say,

Code:
//MainDlg.cpp
DDX_Control(pDX, IDC_ComboBrightness, m_Brightness
I was told that I could do something like:

Code:
//ImageDlg.h
public:
ImageDlg(CWnd* pParent = NULL, CComboBox m_Brightness); // standard constructor

But I get errors including: Missing default parameter for parameter 2

I also need to pass the image array, is that perhaps the same method?

View 6 Replies View Related

C :: How To Typecast Correctly

Feb 17, 2015

so i have this problem with my code ( not running)i want to read ( 2 double numbers x,y) and ( one integer z) then calculate reminder of x and y ( after they both converted to integer) and the formula : x^2 + y^2 + z^2and : x^z + y^z

here is what i came up with :

Code:
// compute.c

#include<stdio.h>
#include<math.h>
int main(void)
{

[Code]....

it also says in q : be sure to test the user input to make sure x,y,z are positive . any negative or zero should not be accepted and must print error msg ==> do i have to have an if statement here ? or the while loop is enough ?

View 9 Replies View Related

C :: How To Use Pow Function Correctly

Jan 23, 2015

I'm working on a school assignment that asks us to make code calculating the quadratic formula.

Code:

#include <stdio.h>
#include <math.h>
int main(void) {
double a = 0;
double b = 0;
double c = 0;
double discriminant = 0;
double solution = 0;
double solution2= 0;
}

[code]....

View 4 Replies View Related

C++ :: Board Not Printing Correctly

Jul 19, 2013

I'm writing a version of the classic Snake game. However, my board is not printing correctly. The right hand border is in the incorrect location. Also, when I randomly generate where the food ('X') is located, it only generates on the edges of the boundaries.

#include <iostream>
#include <cstdlib>
using namespace std;
const int ROWS = 21;
constint COLS = 61;

[code].....

View 5 Replies View Related

C++ :: GPA - Program Not Averaging Correctly?

Feb 7, 2015

My program isnt averaging correctly.

#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;

struct nameGPA {

[Code] .....

View 4 Replies View Related

C++ :: CPP File Not Opening Correctly?

Nov 2, 2014

When I try to open the cpp source in Visual Studio, it just opens a blank notepad window. The cpp file says its 4 kb and there was code in it.

View 5 Replies View Related

C++ :: Calculations Are Done Correctly But Showing Zero

Nov 26, 2013

#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int SZ = 55;

[Code] ....

View 1 Replies View Related

C/C++ :: Do-while Loops Not Working Correctly

Oct 28, 2014

I have an assignment for class .. It works, the do-while loop isn't working correctly. Once I am doing inputting information for any employee It should ask to continue. It doesn't, It skips that loop and prompts to enter the type of employee again.

#include <iostream>
#include <iomanip>
using namespace std;
int main( ) {
char empInput;
char continueResponse;

[code].....

View 3 Replies View Related

C/C++ :: Won't Delete Entries Correctly

Mar 5, 2015

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

[Code]....

It compiles just fine and it will add new entries and print the entries just fine but when I go to delete an entry it will delete it but it will mess up the one before it.

View 8 Replies View Related

C++ :: Object Data Not Updating Correctly

Dec 14, 2013

I am writing a program that manages a group of tool bins. This group is handled as an object that is an array of two element structures called InvBin. I initialize the bins with data from a file which contains the descriptions and initial quantities. I also have functions to add or subtract items from a bin and a function to display a report of the description and quantity of all of the bins.

The add and remove functions work correctly based on the cout statement in the functions, however when I display the report, it displays the initial quantity instead of the new quantity. In addition, when I use the add and remove functions again on the same bin, they use the initial quantity.

These are the add and remove functions and the report function from the main program.

Code:
//Adds an item to a bin
void addItem(HANDLE screen, BinManager tools, int &count) {
int binNum;
int addNum;
system("cls");

[Code].....

View 2 Replies View Related

C :: How To Correctly Multiply With Negative Numbers

Jul 24, 2013

I've been working on this program to create a simple desk calculator for a school assignment, and I managed to finish. All we had to do was add, subtract, multiply, and divide positive integers - and I was able to do that just fine. This program got me thinking though, because I do not know how to write commands to multiply/divide negative numbers.

In fact, when I divide a number like 21 by 4, it comes out to 5 because I don't know how to allow it to compute remainders (which wasn't a requirement for my program). This intrigued me so I've been trying to figure it out for the last few days but to no avail. Here's my code:

Code: void flush_buffer(){
int ch;
while ((ch = getchar()) != '
' && ch != EOF);

[Code]....

And just know that my code works perfectly fine, I'm not here for troubleshooting it. I just want to know what I can change to allow negative values to be correctly computed.

View 12 Replies View Related

C# :: Not Loading Dynamic Array (128,8) Correctly

Feb 14, 2013

Code:
public void dam_data_setup() {
// fill list
damgtype.Add( den1);
damgtype.Add( den2);
damgtype.Add( da1);
damgtype.Add( da2);
damgtype.Add( db1);
damgtype.Add( db2);

[Code] .....

This is a genetics program and is to parse the source array and write all possible combinations to a new array. All sections but dilute work correctly. For some reason the dilute's Boolean is not testing true when it should. This is causing data corruption.

View 3 Replies View Related

C :: Why Can't Get Info From Text File Correctly

Dec 21, 2013

the info gotten from the text file are all wrong, i can't find any problem with my code,

Code:

#include<stdio.h>
FILE *f;
typedef struct prd {
char name[30];
char code[30];
char idt[30];
float price;

[code]....

View 7 Replies View Related

C++ :: Constant Char Not Being Interpreted Correctly

Oct 23, 2013

I am trying to use libXl to output text from a C++ program to an Excel file. The problem is coming with this library function:

bool writeStr(int row, int col, const wchar_t* value, Format* format = 0)

Writes a string into cell with specified format. If format equals 0 then format is ignored. String is copied internally and can be destroyed after call this method. Returns false if error occurs. Get error info with Book::errorMessage().

If I give input as a string literal like "Hello World" it is displayed correctly. However, if I try to give input as a variable of type const char*, it displays garbage.

Following is my code. MyCompany::company is a QString.

const char* companyName = MyCompany::company.toStdString().c_str();
sheet->writeStr(4, 0, companyName, companyFormat);

View 3 Replies View Related

C++ ::  Adding Fractions - How To Align Correctly

Mar 18, 2014

Ii need an output like this...

#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <ctype.h>
#include <locale>
using namespace std;

int EquationNum (int Num1, int Den1, int Num2, int Den2);

[Code] ....

View 9 Replies View Related







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