Why wont this work?? It shows the right answer in the input function but some wierd number in the main... any ideas?
I also tried declaring the structure globally and still it works in the input function but gives me a zero in the main. Any help would be greatly appreciated.Code:#include<iostream.h> #include<iomanip.h> #include<conio.h> #include<string.h> #include<math.h> #include<time.h> #include<stdlib.h> struct info { int number; }; void input() { info vars; cout<<"Enter a number: "; cin>>vars.number; /****************************************** IT WORKS HERE ******************************************/ cout<<vars.number; } main() { info vars; input(); cout<<endl; /****************************************** BUT NOT HERE ******************************************/ cout<<vars.number; getch(); }
Code:#include<iostream.h> #include<iomanip.h> #include<conio.h> #include<string.h> #include<math.h> #include<time.h> #include<stdlib.h> struct info { int number; }; info vars; void input(info vars) { cout<<"Enter a number: "; cin>>vars.number; /****************************************** IT WORKS HERE ******************************************/ cout<<vars.number; } main() { input(vars); cout<<endl; /****************************************** BUT NOT HERE ******************************************/ cout<<vars.number; getch(); }



LinkBack URL
About LinkBacks


