1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Creating Menu system

Discussion in 'C++' started by Nuja, Jun 24, 2009.

  1. Nuja

    Nuja New Member

    Joined:
    Jun 23, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello,

    Recently I've been trying to make a menu system, no matter what I try to come up with I can't seem to get any of my methods to work together.I have asked some of my teachers but they seem like they didn't get what I was asking, Heres whats required to do the project :


    · ​
    Create a menu system that gives the user the option of seeing their fortune OR stock
    market advice.

    · ​
    Use the same choices for your fortune as the project in Workshop 7.

    · ​
    If the user chooses to get Stock Market advice, generate a random number that will help
    choose which advice to give. The options are:

    o ​
    “You should definitely buy!”

    o ​
    “Sell! Sell! Sell!”

    o ​
    “Heck if I know. Go ask your stock broker.”

    · ​
    Make one function for the fortune teller option and another function for the Stock Market
    advice option.

    · ​
    For the fortune teller function, use the if, if else syntax to write your function.

    · ​
    For the stock advice option you should use the Switch statement to write your function.

    · ​
    After the user has their results, the program should ask the user if they want to quit. If
    they want to quit, the program will end. If not, the program should display the menu again

    and let the user choose again.

    Please note, this is for a class Iam doing. I'am not asking for someone to create it for me, I just want help or even tips on how or what would be better to do.

    Here is my code :

    Code:
    [SIZE=2][COLOR=#0000ff]
    #include[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#a31515]<iostream>
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#a31515]<stdlib.h>[/COLOR][/SIZE][SIZE=2] 
    [/SIZE][SIZE=2][COLOR=#0000ff]#include[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#a31515]<time.h>
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]namespace[/COLOR][/SIZE][SIZE=2] std;
    [/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] main()
    {
    srand(([/SIZE][SIZE=2][COLOR=#0000ff]signed[/COLOR][/SIZE][SIZE=2])time(NULL));
    [/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] theNumber;[/SIZE][SIZE=2][COLOR=#008000]// holds a random number for the fortune teller.
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] theStock; [/SIZE][SIZE=2][COLOR=#008000]//holds a random number for the stock market.
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] question;[/SIZE][SIZE=2][COLOR=#008000]//used to hold the question.
    [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]char[/COLOR][/SIZE][SIZE=2] stock;[/SIZE][SIZE=2][COLOR=#008000]// used to hold the question.
    [/COLOR][/SIZE][SIZE=2]
    
    theStock = 1 + rand() % 3;
    
    [/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] menu;[/SIZE][SIZE=2][COLOR=#008000]// declares menu variable, this will be used over and over
    [/COLOR][/SIZE][SIZE=2]
    
    
    cout<<[/SIZE][SIZE=2][COLOR=#a31515]"1.Fortune Teller."[/COLOR][/SIZE][SIZE=2]<<endl;
    cout<<[/SIZE][SIZE=2][COLOR=#a31515]"2.Stock Market Advicer."[/COLOR][/SIZE][SIZE=2]<<endl;
    cout<<[/SIZE][SIZE=2][COLOR=#a31515]"3.Quit."[/COLOR][/SIZE][SIZE=2]<<endl;
    cin>>menu; 
    [/SIZE][SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][SIZE=2](!= 3)
    {
    
    [/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (menu == 1)
    {
    cout<<[/SIZE][SIZE=2][COLOR=#a31515]"Welcome to the Fortune Teller."[/COLOR][/SIZE][SIZE=2]<<endl;
    cout<<[/SIZE][SIZE=2][COLOR=#a31515]"Enter your question."[/COLOR][/SIZE][SIZE=2]<<endl;
    cin>>question;
    
    theNumber = 1 + rand() % 4;
    [/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (theNumber == 1)
    {
    cout<<[/SIZE][SIZE=2][COLOR=#a31515]"Yes,I believe so!"[/COLOR][/SIZE][SIZE=2]<<endl; 
    }
    [/SIZE][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (theNumber == 2)
    {
    cout<<[/SIZE][SIZE=2][COLOR=#a31515]"No way."[/COLOR][/SIZE][SIZE=2]<<endl;
    
    }
    [/SIZE][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (theNumber == 3)
    {
    cout<<[/SIZE][SIZE=2][COLOR=#a31515]"Most likely, yes."[/COLOR][/SIZE][SIZE=2]<<endl;
    
    }
    [/SIZE][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (theNumber == 4)
    {
    cout<<[/SIZE][SIZE=2][COLOR=#a31515]"Try again tomorrow."[/COLOR][/SIZE][SIZE=2]<<endl;
    
    }
    }
    [/SIZE][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (menu == 2)
    {
    cout<<[/SIZE][SIZE=2][COLOR=#a31515]"Welcome to the Stock Market Advicer."[/COLOR][/SIZE][SIZE=2]<<endl;
    cout<<[/SIZE][SIZE=2][COLOR=#a31515]"Enter your stocks."[/COLOR][/SIZE][SIZE=2]<<endl;
    cin>>stock;
    theStock = 1 + rand() % 3;
    [/SIZE][SIZE=2][COLOR=#0000ff]switch[/COLOR][/SIZE][SIZE=2] (theStock)
    {
    [/SIZE][SIZE=2][COLOR=#0000ff]case[/COLOR][/SIZE][SIZE=2] 1:
    cout<<[/SIZE][SIZE=2][COLOR=#a31515]"You should definatly buy!"[/COLOR][/SIZE][SIZE=2]<<endl;
    
    [/SIZE][SIZE=2][COLOR=#0000ff]case[/COLOR][/SIZE][SIZE=2] 2:
    cout<<[/SIZE][SIZE=2][COLOR=#a31515]"Sell! Sell! Sell!"[/COLOR][/SIZE][SIZE=2]<<endl;
    
    [/SIZE][SIZE=2][COLOR=#0000ff]case[/COLOR][/SIZE][SIZE=2] 3:
    cout<<[/SIZE][SIZE=2][COLOR=#a31515]"Heck if I know. Go ask your stock broker."[/COLOR][/SIZE][SIZE=2]<<endl;
    }
    }
    
    [/SIZE][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2]( menu == 3)
    {
    }
    }
    
    system([/SIZE][SIZE=2][COLOR=#a31515]"PAUSE"[/COLOR][/SIZE][SIZE=2]);
    [/SIZE][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2] 0;
    
    }
    [/SIZE]
    Whenever I try to compile it, This is what It gives :

    Code:
    [SIZE=1]
    ------ Build started: Project: project2, Configuration: Debug Win32 ------
    Compiling...
    project2.cpp
    c:\documents and settings\user\desktop\c++ assignments\project2\project2\project2.cpp(27) : error C2059: syntax error : '!='
    c:\documents and settings\user\desktop\c++ assignments\project2\project2\project2.cpp(28) : error C2143: syntax error : missing ';' before '{'
    Build log was saved at "file://c:\Documents and Settings\User\Desktop\C++ Assignments\project2\project2\Debug\BuildLog.htm"
    project2 - 2 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    [/SIZE]
    Thanks to anyone who can help me.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    OK, well start by thinking about the exact literal meaning of the error, and have a look at the line it pertains to. So for the first error we have:
    error C2059: syntax error : '!='
    and while I don't have line numbers so I can't tell which line it is, I'd guess it was on this line:
    Code:
    while(!= 3)
    
    Can you see anything wrong with that line?

    I'm not sure what the next error means specifically but often one actual mistake in the code can lead to several errors so once you've fixed the above, recompile and see what errors you get.

    Then before posting if there are any more errors, have a good think about the exact literal meaning of the error and have a close look at the relevant line.
     
  3. Nuja

    Nuja New Member

    Joined:
    Jun 23, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    The thing is, I already tried to look at that error, couldn't figure it out since

    != is an operator, correct?
    so while ( != 3) <--Should mean "run until user hits 3rd option."

    Thats why I posted for help, I'm still unsure where to put the while(!=3) but I thought it should go under the options near the end since "do" statement is on the top.
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    OK. Yes, != is an operator that takes TWO arguments. The correct syntax is
    Code:
    while ( _something_ != 3)
    
    where _something_ is a variable, function call that returns int, or anything else that evaluates to an object that has a handler for the != operator. So in your case _something_ is probably menu.
     

Share This Page