1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Problems With Calling A Function

  1. Oct 31, 2007 #1
    1. The problem statement, all variables and given/known data
    I have to write a function that first prints a list of 6 choices, tells a user to choose one of the six choices using the number 1-6, then either return the number they chose or -99 if they chose a number less than one or greater than 6. Then, I have to call this function and if they chose a number between 1 and 6, report this number, but if they chose outside of the range, print you did not choose a stock.

    3. The attempt at a solution
    I have the function done. I just don't know how to go about calling it. What I have now is:

    if(stockMenu() ==-99)
    cout<<"You did not choose a stock"
    else
    cout<<stockMenu()

    Obviously you can see the problem with this way, as the function runs twice. How can I do this?
     
    Last edited: Oct 31, 2007
  2. jcsd
  3. Oct 31, 2007 #2

    George Jones

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    menu = stockMenu();
     
  4. Oct 31, 2007 #3
    Haha I can't believe I couldn't think of that. Thanks alot!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Problems With Calling A Function
Loading...