C++ :: How To Pass Structure Values Between Functions

Dec 29, 2012

Code:
struct NewPlayer {
int level;
int intelligence;
int damage;
};
int CharacterInfo(NewPlayer MageWizard, int Clevel,int Cint, int Cdam)

[Code] .....

View 1 Replies


ADVERTISEMENT

C/C++ :: How To Pass Structure Variables Between Functions

Jul 13, 2014

I have a project for class where I have to create a structure and get user input for 3 structure variable arrays of 10. I am trying to figure out how I can use the same function to fill my different section of variables.

My Structure is an employee file of ID number, name, hours, payrate, and then gross pay. I have to create a function for each input function. I am confused on how to pass the structure variable so that I do not have to write 3 functions for each input. I would like to be able to get all the info for the first structure variable and then recall the same 5 functions for the next before moving along. I hope that I have been able to make this clear. Here is my code:

#include<iostream>
#include<iomanip>
#include<cctype>
#include<string>
#include<cstring>
using namespace std;
struct PayPeeps_CL//Payroll Structure {

[Code] .....

View 14 Replies View Related

C :: Pass Values In Functions And Writing Them To A Txt File

Aug 23, 2013

This code is for fun, and have it doing a lot of what I want it to, just not all. I want random generated to write to a txt file. I tried to use an array but that failed. I wanted to use an array because i am only passing one value. Which makes sense since the random generated function is an int.

I made the fprintf as a comment but hopefully soon it will be able to send the values to the txt file. After that I will tackle the function.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define HIGH 49
#define LOW 1
int random_generated()

[Code]...

View 11 Replies View Related

C++ :: Pass Pointer To Member Function (polymorphic Structure)?

Jan 3, 2015

I am trying to create a callback system for input events in my game engine.

Here is a cut down version of the EventManager.h file

#include "Controls.h"
#include "Object.h"
enum MouseEventType{PRESSED, POINTER_AT_POSITION, PRESSED_AT_POSITION };

[Code].....

This works if the function pointer being passed to the event manager is not a member function.

I have two other classes Scene and Object that could potentially use this EventManager to create callback events. Scene and Object are both pure virtual objects. How can I pass a pointer to a member function of the child classes of both Scene and Object? I am fine with just having two separate watchEvent functions for Scene and Object but how do I pass the type of the Object or the type of the Scene? The child classes are unknown as they are being created by someone using this game engine.

For example, if I want to make a player object it would be something like

class PlayerObject : public Object{...};

Now that PlayerObject type has to find its way to PlayerObject::functionToCall(). I think I need templates to do this but, since I never used them before

This is how I intend to use this

class OtherScene : public Scene{
void p_pressed(void){
//pause
}

[Code].....

View 6 Replies View Related

C :: How To Pass Arrays To Functions

Sep 23, 2014

I have read about it in my book and also on this website but i still have things uncleared....

View 11 Replies View Related

C :: Pass Variables Between Functions

Jun 29, 2014

I'm playing around with GTK+ 2.x and currently I have a button to call a function like so:

Code:
void selectmod(GtkWidget *downloadbutton, GtkComboBox *modlist, gchar *data){
gchar *mod = gtk_combo_box_get_active_text(modlist);
printf("
%s", mod);
}

How can I pass the *mod variable to another function?

View 9 Replies View Related

C++ :: Can't Pass To Functions With Pointer

May 25, 2013

I get a run time error saying something about memory locations when I run this program.How can I make this program work using pointers?

//this program converst miles to km
#include<iostream>
#include "std_lib_facilities.h"

[Code]....

View 1 Replies View Related

C++ :: How To Pass Arguments From Other Functions To Main

Sep 6, 2013

How to pass arguments from other functions to main. i want to write a program like nano well not exactly like nano editor. I have a function f_read(char* filename[]), and fopen() get filename[1] as file name and *filename[2] as "r" read mode and rest of the code will read from a file.

I want is this char filename[] to main(int argc , char argv[])

how can i do that??

View 4 Replies View Related

C++ :: How To Pass Same Instance Of Object In Two Functions

Feb 25, 2014

I need to send same instance of object of a class in two function (Main function and thread function). The class is something like this:

//The class need to have constructor.
Class ABC {
public:
DWORD *IdG;
ABC(int number) {
IdG = new DWORD[number];
}
}obj(32);

The obj(32) is called in following two function. Function F1 is called using thread in main function.

void F1() {
obj.test;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
obj.test1;
_beginthread(F1,0,(void*)number);
}

The code works well when the object of class ABC is created as shown above. My problem is the value that is passed in the object ('32') is to be read from the file.

If I read the file and create object separately in Main function and function 'F1' then , function 'F1' is not executed.

How to create same instance of object for Main function and function 'F1' with value passed in the object taken from the file.

View 1 Replies View Related

C :: Why Cannot Pass The Address Of String During Printf Or Scanf Functions

Jan 24, 2013

Why do we not pass the address of the string during printf or scanf functions like we do for Integer or float variable types?

View 2 Replies View Related

C++ :: Program Using Switch Statements To Pass Multiple Functions

Oct 1, 2014

I am returning area from areaCircle(), but do not know how to print it in main. I know this program has lots of errors, two cases that I have listed.

Not sure how to properly list multiple function calls in a switch statement, and how to print one's return from main.

int main() {
char choice;
double area;
showMenu(choice);
switch (choice) // If input is C, use getRadius, areaCircle and count, then print the are
{
case 'C': void getRadius(),double areaCircle(), void count(bool display = false);

[Code]...

View 5 Replies View Related

C++ :: Pass Values By Reference

Nov 7, 2014

I built a program that finds the average amount of days missed per employee. I am now attempting to modify my program to pass values by reference rather than passing by value. I created 3 functions: int numOfEmployees(); int numOfDays(int); double avgDays(int, int);

in the prototype I use the ampersand sign int numOfDays(int&);
in the actual function I use numOfDays(int& employees)

I am just not able to get the call to the function to work the program will crash when I modify it with the ampersand signs.This is the original code I am trying to modify:

#include <iostream>
using namespace std;
int numOfEmployees(); //Prototype for numOfEmployees
int numOfDays(int); //Prototype for numOfDays
double avgDays(int, int); //Prototype for avgDays

[code]....

View 1 Replies View Related

C/C++ :: Pass Values By Reference?

Nov 7, 2014

I built a program that finds the average amount of days missed per employee. I am now attempting to modify my program to pass values by reference rather than passing by value. I created 3 functions:

int numOfEmployees(); int numOfDays(int); double avgDays(int, int);

in the prototype I use the ampersand sign int numOfDays(int&);
in the actual function I use numOfDays(int& employees)

I am just not able to get the call to the function to work the program will crash when I modify it with the ampersand signs. I know I have to re-work my program, but I am having a hard time understanding how.

This is the original code I am trying to modify:

#include <iostream>
using namespace std;
int numOfEmployees(); //Prototype for numOfEmployees
int numOfDays(int); //Prototype for numOfDays
double avgDays(int, int); //Prototype for avgDays

[Code]......

View 1 Replies View Related

C# :: Pass Values Between Forms Using Get And Set Properties?

Jan 15, 2015

Well I know how to pass values between forms using get and set properties. But the problem with it is everytime I want to pass values from form2 to form1 it doesn't appear. To make it appear I have to type form1.Show(); which open form1 a second time and then show the value. Is there any way I could make it appear without using form1.Show();?

View 9 Replies View Related

C/C++ :: How To Pass Multiple Values From One Function To Another

Mar 4, 2015

I need to pass multiple values from one function to another and how to do this. Here is my code so far.

#include <iostream>
#include <string>
#include <cctype>
#include <fstream>
using namespace std;
//Function Prototypes//
int charString(string, string, string);
string reverseString(string, string, string);

[Code]...

I basically need to take line1, line2, and line3 and return them to the reverseString function. Also, I am not allowed to do anything like make my own classes. I have to stick to the basics and no higher level programming techniques since we have not learned them yet.

View 5 Replies View Related

C++ :: Passing Structure Arrays To Functions?

Oct 31, 2013

Description: Use functions and structures to simulate storage in a warehouse

*/
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
struct Bin {std::string name; int Quantity;}; //create a structure for "Bin"

[code].....

I keep getting a linker error on every function. what am I doing wrong?

View 2 Replies View Related

C/C++ :: Passing Structure Addresses To Functions

Mar 20, 2014

What this is, is a more recent assignment and my question is if my errors are directly related to passing structure addresses to functions. I've tried several syntax variations at the beginning of my loops such as this one:

while (choice != "Q" || "q")

But the loops will not run since I introduce polar to rectangular and the choice element. My last working code was rectangular to polar and all of it worked fine.

#include<iostream>
#include<cmath>
using namespace std;
//structure declarations
struct polar
{
double distance; //distance from origin
double angle; //direction from origin

[Code] ....

View 14 Replies View Related

C :: Unable To Pass Values To Struct As A Byte

Jul 19, 2014

I am using a struct and tying to send values to it as byte value

Code:

#include<stdio.h>
typedef struct{
unsigned r1:1;
unsigned r2:1;
unsigned r3:1;

[Code] ....

Error: invalid suffix "b00100000" or incompatible types in assignment

I am able to access the member as Range.r1 = 1; and have no problems. I want to send data whole at once, but how ?

View 8 Replies View Related

C++ :: Assign Values To A Dynamic Memory Structure?

Dec 27, 2014

I create some code that assign values to a dynamic memory structure. I'm not sure why one code works and the other crashes when it assigns a value.

Working Code

#include <iostream>
using namespace std;
struct WorldOjectCollisionMap
{

[Code].....

View 6 Replies View Related

C/C++ :: Not Displaying Values Inside Structure Array (GCC)?

Apr 22, 2014

#include <stdio.h>
#include <string.h>
#define MAX 22
struct inven {
int Iid;
double uprice;
int uoh;
char name[MAX];

[code].....

doesn't seem to want to display the disp* fucntions at all

View 2 Replies View Related

C/C++ :: How To Assign Values From Text File To Structure Of Arrays

Sep 5, 2014

have to do an election program in C.

There are 7 candidates and 365 votes in total. I need to do this using an array of structures. I need to read from a text file each of the names of the candidate and the number of votes they get. At the end i need to output the winner of the election.

Here is a sample of my code so far

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct candidates {
char name[20];
int votes;

[code]....

Here is a sample of my text file:

Robert Bloom
John Brown
Michelle Dawn
Michael Hall
Sean O’Rielly
Arthur Smith
Carl White

1 2 4 5 1 2 3 4 4 1 2 3 7 4 4 5 3 7 7 7 7 7 7 7 7 7

Each candidate gets +1 vote for their number electionCandidate[0] for each one he gets one vote and so on for the rest. 365 voters in total.

I was able to input the name for each Candidate from the text file. Now the problem is putting each vote to the corresponding candidate. Also any vote that is above 7 is a spoilt vote which i am trying to count in the above code. The code compiles but it crashes.

I am using while(!feof) but it seems that its not working or this is not the correct way.

View 6 Replies View Related

C++ :: Functions Which Return Values

Nov 27, 2014

Write a function named cointoss that simulates the tossing of a coin.

When you call the function, it should generate a random number in the range of 1 through 2.

If the random number is 1, the function should display "heads".

If the random number is 2, the function should display "tails".

Demonstrate the function in a program that asks the user how many times the coin should be tossed, and then simulates tossing the coin that number of times.

Report the total number of heads and tails.

View 2 Replies View Related

C++ :: Passing Values To Functions?

Jul 29, 2013

I am trying to get some confirmation about how to pass to functions. If you want to assign default values to certain parameters, and have others defined inside the body of int main(), then the parameters which will have default values go at the end of the list. Is that correct?

i.e. The following code is wrong, because we cannot leave a black in the function call on the third line of the main function. However, if we switch the prototype to void Passing (int a, int c, int b = 1); and the function definition to void Passing (int a , int c, int b) everything will be okay and we can call the function as Passing (a, c).

In brief, we cannot do this EVER:
Passing( a, , c)right?
#include <iostream>
using namespace std;

[Code]......

View 4 Replies View Related

C++ :: Functions Returning Values?

Apr 9, 2014

I have an assignment in my C++ class that is to create a menu based coffee shop program. Here is what I have so far:

#include<iostream>
#include<cmath> //doubt this is needed but i added it just in case
using namespace std;

[Code]....

View 19 Replies View Related

C/C++ :: Why Won't Functions Process New Values

Nov 5, 2014

I was given an assignment where I have to input two points (four integers) on a Cartesian plane from a file and then process it using functions. My professor is very particular so the comments are a bit excessive, but here's what I have.

double radiusFn(double, double, double, double);//4 double values, one for each point. All points are needed for the calculation of distance in this function.
double diameterFn(double);//Only uses one double value - the radius. Both functions below use the same value.
double circumferenceFn(double);
double areaFn(double);
int main() {

[code].....

The file reads:

Quote

1 2 3 4 5 6 7 8 9 10 11 12

View 2 Replies View Related

C++ :: Share Values Between Functions In Same Class?

Mar 22, 2013

Code:

#ifndef CANDIES_H
#define CANDIES_H
#include <iostream>
#include <fstream>
#include <Global.h>
class Candies

[Code]...

Code:

#include "Candies.h"
#include <Windows.h>
#include <iostream>
#include <fstream>
#include <sstream>

[Code]...

When I tested it, the file name in getName() outputted the right file name. However the file name in loadName() does not print out anything in the console window.

I want it to be so that the strings in [I]name_addTXT.c_str() in both functions are equal.

View 4 Replies View Related







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