mhking04 Posted September 3, 2004 Share Posted September 3, 2004 hey, i have a method called CalculateRepayment, however when the code is done, i need it to go back to the main method. how do i do this? cheers Link to comment Share on other sites More sharing options...
0 smurfiness Posted September 3, 2004 Share Posted September 3, 2004 Program flow returns to the line immediately after the function call when a function exits. Link to comment Share on other sites More sharing options...
0 mhking04 Posted September 3, 2004 Author Share Posted September 3, 2004 im sorry dannysmurf, but that makes no sense. could you explain that better please. thanks. matt Link to comment Share on other sites More sharing options...
0 Glowstick Posted September 3, 2004 Share Posted September 3, 2004 It made very well sense. A method automatically returns to the caller when it ends. When you call method Foo() from main(), and Foo() ends, your application continues in main() where it left off. Link to comment Share on other sites More sharing options...
0 +virtorio MVC Posted September 4, 2004 MVC Share Posted September 4, 2004 int CalculateRepayment(int pay) { 4 return (pay *.7) / 12; } void main() { 1 int res, val; 2 cin >> val; 3 res = CalculateRepayment( val ); 5 cout << val; } The numbers show which order things happen. That is the best way I can explain it. Link to comment Share on other sites More sharing options...
0 mhking04 Posted September 4, 2004 Author Share Posted September 4, 2004 ok, this is the code in main (); public static void main(String[] args) { if (iMenu == 1) { bContinue = false; CalculateBorrow(); } } that makes it go to my other code public static void CalculateBorrow() { System.out.print("test message"); } now the main code has a menu code in it which needs to be called again (i didnt append the code) when it goes to CalculateBorrow, it shows the test message then quits the program. i need to to show the message, then go bak to main to reshow the message. if you guys ahave expained this above, i am sorry but i am new to java and am not completely familiar with it. thanks guys matt Link to comment Share on other sites More sharing options...
0 gigapixels Veteran Posted September 4, 2004 Veteran Share Posted September 4, 2004 Ummm... That's very strange. I don't understand why the program would just stop afterward. It should go on to the code immediately after the CalculateBorrow() method was called. Check your code for any errors. Make sure that you have the code that you did not append in the right place. That's my only idea as to why it isn't working. Link to comment Share on other sites More sharing options...
0 bithub Posted September 4, 2004 Share Posted September 4, 2004 You need a loop for the menu to be called again. Do a search for c++ loops and Im sure you will find a good tutorial. Link to comment Share on other sites More sharing options...
0 smurfiness Posted September 4, 2004 Share Posted September 4, 2004 Ummm... That's very strange. I don't understand why the program would just stop afterward. It should go on to the code immediately after the CalculateBorrow() method was called. Yes, which is exactly what it does. If you'll notice, there IS no code after the call to CalculateBorrow. Link to comment Share on other sites More sharing options...
0 mhking04 Posted September 4, 2004 Author Share Posted September 4, 2004 i worked it out. i had a boolean set up, however when i was telling it to move to the next method, i was setting boolean = false. i removed this code and it works now thank you everyone who tried to help me. matt Link to comment Share on other sites More sharing options...
0 gigapixels Veteran Posted September 5, 2004 Veteran Share Posted September 5, 2004 Yes, which is exactly what it does. If you'll notice, there IS no code after the call to CalculateBorrow. Ummm... If you read, he said he did not append that code... Anyway, glad you could get it working. Most of the time it ends up being an error in the code that we don't see until we look at it 10 more times. Don't you hate it when that happens? Link to comment Share on other sites More sharing options...
Question
mhking04
hey,
i have a method called CalculateRepayment, however when the code is done, i need it to go back to the main method.
how do i do this?
cheers
Link to comment
Share on other sites
10 answers to this question
Recommended Posts