I need to pass a file as a parameter to the get_corners function, and then fill an array with an unknown quantity of data, and return the number of data to main.
Compiling this generates some messages about unused variables, which is fine for this incomplete code.
Running it just generates a blank screen. So that obviously needs to be fixed. What am I doing wrong?
I have tried moving fpin = fopen ("c: emphw12.txt","r"); to the main function, then function call to get_corners, and then closing the file after return, but same blank screen.
hw12.txt is simply:
4,0,4,7.5,7,7.5,7,3,9,0,7,0,4,0
The game is going to be an RPG where you take turns attacking enemies. Your character will be able to attack/defend/use item/run/use magic spell. For now, we just want the bare basics - for a character to be able to do a generic attack and to be able to fight a generic enemy (so we're not worried about items and such things yet).
Our cpp files are: hero.cpp (which is actually the main file... and should be renamed to something better, admittedly), enemyStats.cpp (contains a class for enemies that lets you declare its HP/attack/etc), playerStats.cpp (see previous; but for your character) and attack.cpp, which contains the following:
int attackFunction(player myPlayer, enemy myEnemy) { print("Your player attacked for %d damage, bringing the wolf down to %d HP.", myPlayer.getAttack(), myEnemy.getCurrentHealth-myPlayer.getAttack()); }
We barely started, but we're already stuck on that part. I managed to make the program run just fine in terms of giving the player and enemy stats and reading it, but whenever I try to run this code in my hero.cpp (inside of main):
attackFunction(warrior, wolf);
it tells me that "enemy" has not been declared.
If I run the same code, but without any references to the wolf/enemy (so just warrior/myPlayer), it runs perfectly fine. Likewise, the program runs perfectly fine if I don't use attack.cpp and put the function directly inside of the main hero.cpp folder.
I have been working on code for quite some time and am able to successfully read in a text document and take certain words and information that I need. The issue is that I need to read in close to 100 plus documents and was wondering how I could read in the multiple documents. I thought about creating a structure of arrays and have each text document be an element and walk through taking each document but I am not sure how this works.
I want to use one median function "selectfunction" to choose one of the 2 other functions at random to pass my 2-dim array to the selected function. There is a problem in the median function
#include <iostream> #define random(x)(rand()%x) // for random number between numbers of 0 and 1 using namespace std; void proc1 (int iArray[][2]); void proc2 (int iArray[][2]); void selectfunction(int iArray[][2]); int A[4][2] = {{1, 2} , {3, 4} , { 5, 7} , {8, 1} };
I am trying to pass function as argument to another function. My idea is to write function that can works with any type of array, and for it to be able to compare array items I'd like to use my own compareTo function. But I need to be able to pass function to use for comparing argument.
To say it short I am trying to write my own qsort that would take compareTo as one argument just like original qsort does.
Here is my code
// test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <windows.h> template <class T> int compareTo( T a,T b){
[code]....
and errors
1>d:my documentsvisual studio 2012projects est est est.cpp(29): error C2896: 'void DoSomething(T,int (__cdecl *)(T,T))' : cannot use function template 'int cmp(T,T)' as a function argument 1> d:my documentsvisual studio 2012projects est est est.cpp(8) : see declaration of 'cmp' 1>d:my documentsvisual studio 2012projects est est est.cpp(29): error C2784: 'void DoSomething(T,int (__cdecl *)(T,T))' : could not deduce template argument for 'T' from 'int [3]' 1> d:my documentsvisual studio 2012projects est est est.cpp(21) : see declaration of 'DoSomething'
How to pass an int that I got from user input into a function to use it. I am trying to print out the words to a string of numbers.
I got the input from user. I got an absolute value of the input. I then separate the string into individual digits and name them. I can print these out. Then I started my if statement by checking if the original input was zero, and if it is, printing zero and exiting. Then I an trying to pass the digits into a switch function and this is where I go off the rails.
The program asks for to ask the user for how many students there are, and how many strawberries they picked. The farm gets to keep half and the students get to keep the rest.
I am using functions and passing values to one function to another. I know I am making it harder then I need to, but I want to work with functions more and passing values. I figured it was better to practice with simple programs.
I want to pass array to function, to fill array with new values and then to print the array in the main. But I have problem because it prints me just array of zeros. Maybe the concept is wrong, I'm new with passing arrays to function.
function:
Code: void printSum(int *return_array) { int return_array[3]; int i; for(i = 0; i < 3 ; i++){ return_array[i] = 5;
Code:
void printSum(int *return_array); int main { int m_return_array[3]; int i,j; for(i= 0 ; i < 3 ; i++){ m_return_array[i] = 0; } printfSum(start,m_return_array);
I need to pass a 2D array to a function. I want to know, where I may have made a mistake. This is the piece of code that I found on the web, and I am using it to allocate my 2D array.
Code: signed char allocate2D( int** arr2D, int rows, int cols ) { int i; arr2D = malloc( rows*sizeof( int* ) ); if( !arr2D ) return -1;
[Code]....
My main function passes the 2D array to the function
Code: signed char read_root_message_file( int **Root_Messages, int *num ) This is how I pass the array in the main function to the above function:
Code: int main( int argc, char *argv[] ) { int **Root_Messages; ... ... Root_Messages = NULL; read_root_message_file( Root_Messages, &num_root_msg );
I am following a tutorial and the topic was passing array to function so i tried to do a BMI calculator by myself. I am using code blocks to compile the codes, it is actually working while using compiler's run button. But when I open the exe file, its closing the window after entering the persons' weights and heights. Here is the code
Code:
// Passing array to function example BMI calculator of n person #include<stdio.h> #include<math.h> void assess(float bmi[],int a); int main(void){ int n,i,j; }
Quick question... how do you pass a list in to a function...
For example forvoid reverseListwhat would the parameters be for my function... I'm trying to put everything in my case R statement in a function so I can make a neat class...
It works, when the object is passed, except for two cases (one where the minus sign shifts) and whenever there is a zero or a negative integer in the denominator.
Also, I'm passing the function like validInput(c);
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?
i have defined an object which is an array of my class called Player now i want to pass this whole array as a parameter in a function, i think it will be done by using pointers but i am not able to figure out how it is done?
Player player[4]; void showscoreboard(" ", int cround){} " " represents the blank where the array should b passed.
I'm familiar with function pointers as the method to pass a function as an argument to another function. However, I recently encountered some other syntax. I have seen in multiple times and in books,so I know it is probably not a syntax error. But I am not totally sure.
#include <iostream> void Function1() { std::cout << "Function1"; } void Function2(void aFunction()) { aFunction(); } // make a param that describes the function the will be given // as a param (return type, identifier,
I was just wondering how is this generally resolved. Let say you have this large function that runs in two modes. In the first mode it evaluates the data passed to a function as a map the the second mode it fills the map. example:
Code: template <typename Map, typename Int> void func(Map & map, Int i){ int z = 0; string zz;
[Code] ....
The point is i do not want to write a large function just to include different modes so i decided to set "i" to be a mode identifier. However when i want to compile my function given two modes i get an error since the modes are not recognized (obviously). if i pass map as
Code: map<int,int> and mode 1 i get an error here : Code: map[z] = z; besause map Code: map[z] expects z to be an int not string and the other way around (though in practice this cannot happen since i set the modes). So am i restricted to writing my function for both modes separately (polimorf.) or there is a way to make my example work.