I'm still a noob in C++ and I was hoping someone could help me with this. My problem is that I would like a function to read a variable made in a previous function.
my code:
Code:
#include <iostream>
using namespace std;
int secondary(); //prototypes
int primary2();
int main()
{
int x, y, input; //i would like "y" to be passed to primary2()
cout<<"input the Primary skill you would like \n";
cout<<"1. flying \n";
cout<<"2. laser \n";
cout<<"3. super strength \n";
cout<<"4. element controller \n";
cout<<"5. dominator \n\n";
cin>>y;
switch (y){
case 1:
cout<<"\nyou chose flying\n\n";
break;
case 2:
cout<<"\nyou chose laser\n\n";
break;
case 3:
cout<<"\nyou chose super strength\n\n";
break;
case 4:
cout<<"\nyou chose element controller\n\n";
break;
case 5:
cout<<"\nyou chose dominator\n\n";
break;
default:
cout<<"\nerror\n\n";
main();
break;
}
cout<< "choose \n";
cout<<"1. another primary \n";
cout<<"2. two secondary\n\n";
cin>>input;
switch (input){
case 1:
primary2();
break;
case 2:
secondary();
break;
default:
main();
break;
}
}
int primary2(int &y)
{
int z;
cout<<"choose another primary\n\n";
cin>>z;
switch (z){ //all the couts are fillers to check for it working
case 1:
cout<<"\ni cant believe this worked\n\n";
break;
case 2:
cout<<"\nhoothoot\n\n";
break;
case 3:
cout<<"\num HI\n\n";
break;
case 4:
cout<<"\nyour still here\n\n";
break;
case 5:
cout<<"\ni have nothing to say to u\n\n";
break;
default:
cout<<"\nerror\n\n";
void primary2(int &y);
break;
}
if (y == z){ //this is where i need the y to be read
cout<<"\nerror\n\n";
primary2();
}
}
int secondary()
{
}
I need help with this