• 0

returning to the main method


Question

10 answers to this question

Recommended Posts

  • 0

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

  • 0

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

  • 0

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

  • 0

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

  • 0
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

  • 0

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

  • 0
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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.