I got a function that enters data to an array. When i call the function i want to store data in element 0 and then exit the function and go back to main. When i call the function for the 2nd time i want it to enter the data in the 1st element and then exit the function and go back to the main. How do i exit the function to go back to main without loosing the spot in the array so when i go back to the function to enter more data in the array i can start off where i left off?
i believe is the correct code however i have recently had trouble using static int's , perhaps if static int i was created outside the function inside main and added to the parameters it could be of some help.
void getCustomer(Customer account[], int s, staticint i)
(and dont forget i in the function call as well)
this would keep the spot of the array however the for loop will need a break in it to return to main unless you only had the for loop run once every time the function is called.
error: storage class specifiers invalid in parameter declarations
error: storage class specified for parameter `i'
those are my errors at my function prototype
did you change the function heading along with the prototype and function call? if so how bout a full code post to help me understand the code better
** sometimes i just need to code trial and error style so code will help me see what needs to get kicked around so to speak
yes the static g will only move up once (with g++;) and keeps its value no matter how many times the function is called ( im sure their are limits ) also you would not necessarily need the while loop inside of the function getCustomer(account[],s) since the code will automatically run once
this would allow you to lose the int i and clean up the code some
you could go with the !6 || z<19 but it could also be z>18 because the do while loop might run again at 18 depending on where the incrementer is in the loop
cout << "Enter 1, 2, 3, 4, 5, or 6: ";
41 cin >> choice;
42
43 while (!cin ||choice < 1 || choice > 6)//!cin allows you to check for char's or string's
//input into cin
44 {
cin.clear();
cin.ignore(200,'n');
45 cout << "Invalide Entery, Please Try Again: ";
46 cin >> choice;
47 }
also the code above still catches numbers that are outside of 1-6 but also catches characters entered and throws a flag so the program does not do something crazy. try entering in an "a" with out the code and then try it with the code to seethe effects. never hurts to have extra backup checks even if they never get used
however im not sure that you would need it now that i look at the code more. if you want to run the program until the user says quit (enters 6) then that statement would stay the same, however if you only want the program to run 20 times have that as a limit in your loop hope this helps with that
I just want the program at MOST to run 20 times. so the user has 20 elements in a array to fill if they would like too. Would there be an more efficient way of doing so? So every time they get out of a function is brings them back to the "menu"??