playing around with functions

hi folks,

i am currently playing with functions and trying to figure out how they work. in my piece of code i am looking at taking a users input and then calling a function and using the users input that i took and having it as an input to my function .

the variable 'data' is what i am taking from the user and when i bring it to the function it doesnt work . what i have read from the book is that data as i see it is called a global variable and it should be defined through the program , but the function cant see it . i dont get this bit . the strStringID if assigned works but its the overlapping part of using data and bringing to the function which i cant get to work. i have got bogged down in this now and i am lost at this stage , i need to play around with this in all forms to get used to them, if any one has any light on this it would help cheers , john. i have a feeling i am doing something wrong with the data type of the function as it clashes with the users input data type , if that makes sense.

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

char fun(string);
char data;

int main()
{ cout << "please enter an id";
cin >> data;
fun(data);
system ("PAUSE");
return 0;
}

char fun ()

{
string strStockID = data;


the rest follows

}
In the function implementation you didn't put the argument, you may want data to be a string instead of a char and the function to be like this:
1
2
3
4
char fun ( string strStockID ) // when calling fun(data), strStockID will be set to the value of data
{
    //something
}
thanks bazzy i'll try this when i get home . ............


i got this from the changes i have made

[Linker error] undefined reference to `fun(std::string)'

from what i read the headers etc are correct for using a string data type from a user

#include <string>
using namespace std;
Last edited on
Topic archived. No new replies allowed.