Hi, I'm a little confused and was hoping someone could help me tidy up this problem. I'm trying to write a program which allows the user to input an address, which then prints it on the screen, and finally sends it to a label printer. The problem I've got is that I've just discovered that variables aren't passed between functions.
I need addressenter() to pass the address to the other functions like menu(), and printlabel()
How do I do this? I've misunderstood the tutorial I think, so I'd grateful if you could clear it up for me.
Thanks
Sorry this is a real shambles, but I can sort it out once I know what to do.
Code:#include <iostream> using namespace std; // prototype address enter function int menu(); void printlabel(); void addressenter(); int main() { cout<<"This program prints single address labels input by the user.\n\n"; addressenter(); print(); cin.get(); } // post-addressenter menu int menu() { x = 0; cout<<"\n\nYour address was: \n\n"; while (x<y) { //Address output here cout<<address[x]<<endl; x++; }; cout<<"\nThe address has to be truncated to 22 chars, is it correct?\n1. Yes\n2. No\n\n"; int m; cin>>m; if ( m == 1 ) { cout<<"Print label..."; } else if ( m == 2 ) { cout<<"Reenter address"; addressenter(1); } else { cout<<"Invalid selection, please try again.\n"; menu(); }; return 0; } int addressenter() { // address enter function // str length is 23 as 22+terminating.char "\0" string address[7]; string addressin; cout<<"Enter the address to be printed.\n"; int x = 0; int y = 0; while (x<7 && y!=1) { //Address input here cout<<"Line "<< x + 1 <<": "; //cin.getline ( address[x], 23, '\n' ); getline(cin, addressin); if (addressin!="") { address[x] = addressin.substr(0, 22); x++; } else { y=1; }; }; y = x; x = 0; cout<<"\n\nYour address was: \n\n"; while (x<y) { //Address output here cout<<address[x]<<endl; x++; }; menu(); return 0; }