### Logical Error: Change value inside void statement

Hi there, I've encountered a slight logical error in my code
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899`` ``````/* Lab06_pensionplans.cpp Purpose : - Create a simple financial application to calculate retirement plans */ #include #include using namespace std; void displayMenu() { system("cls"); cout << "+-------------------------------------+" << endl; cout << "| Golden Years Financial Inc. |" << endl; cout << "|=====================================|" << endl; cout << "| Select: |" << endl; cout << "| 1 => Display Data |" << endl; cout << "| 2 => Change Data |" << endl; cout << "|-------------------------------------|" << endl; cout << "| 3 => One Lump Sum Withdrawal Plan |" << endl; cout << "| 4 => Yearly Withdrawal Plan |" << endl; cout << "| 5 => Comparison of Both Plans |" << endl; cout << "|-------------------------------------|" << endl; cout << "| Q => Quit |" << endl; cout << "+-------------------------------------+" << endl; cout << endl; cout << "Choice => "; } /*#1*/ void displayData(int startingAge, int numOfYears, double lumpSumAmount, double yearlyAmount, double interestRate ) { cout << endl; cout << "Starting Age = " << startingAge << endl; cout << "Nunber of Years = " << numOfYears << endl; cout << "Lump Sum Amount = " << lumpSumAmount << endl; cout << "Yearly Amount = " << yearlyAmount << endl; cout << "Interest Rate (%) = " << interestRate << endl; cout << endl; system("pause"); } /*#2*/ void changeData(int startingAge, int numOfYears, double lumpSumAmount, double yearlyAmount, double interestRate ) { cout << endl; cout << "Starting Age = "; cin >> startingAge; cout << "Nunber of Years = "; cin >> numOfYears; cout << "Lump Sum Amount = "; cin >> lumpSumAmount; cout << "Yearly Amount = "; cin >> yearlyAmount; cout << "Interest Rate (%) = "; cin >> interestRate; } int main() { int startingAge = 55; int numOfYears = 20; double lumpSumAmount = 400000; double yearlyAmount = 25000; double interestRate = 5; char choice; bool done = false; do { displayMenu(); cin >> choice; choice = toupper(choice); switch (choice) { case '1' : displayData(startingAge, numOfYears, lumpSumAmount, yearlyAmount, interestRate); break; case '2' : changeData(startingAge, numOfYears, lumpSumAmount, yearlyAmount, interestRate ); system("pause"); break; case '3' : cout << "Not yet implement" << endl; system("pause"); break; case '4' : cout << "Not yet implement" << endl; system("pause"); break; case '5' : cout << "Not yet implement" << endl; system("pause"); break; case 'Q' : done = true; break; default : cout << "Invalid selection, try again!" << endl; system("pause"); break; } } while (!done); cout << "Good Bye!" << endl; cout << endl; } ``````

Look at case 2, which the user supposed to key in a new input, the problem is the value will never got into main function, I don't know what should I modify with the functions

UPDATE:
Figured out I need to change the
 ``12`` ``````void changeData(int startingAge, int numOfYears, double lumpSumAmount, double yearlyAmount, double interestRate ) ``````

into
 ``12`` ``````void changeData(int &startingAge, int &numOfYears, double &lumpSumAmount, double &yearlyAmount, double &interestRate ) ``````

:D
Last edited on
When you pass variables into your function, you are passing *copies* (different than the ones in your main function), so when the function ends, these copies are destroyed. Look up "pass by reference" for how to do what you want to do.
Hey thanks! :D
I only done the question thanks to google, now I know the exact term to use for this type of question and understand the problem
Topic archived. No new replies allowed.