Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Creating Menu system (http://www.go4expert.com/forums/creating-menu-system-t18163/)

Nuja 24Jun2009 04:31

Creating Menu system
 
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:


#include
<iostream>
#include<stdlib.h>
#include<time.h>
usingnamespace std;
int main()
{
srand((
signed)time(NULL));
int theNumber;// holds a random number for the fortune teller.
int theStock; //holds a random number for the stock market.
int question;//used to hold the question.
char stock;// used to hold the question.


theStock = 1 + rand() % 3;

int menu;// declares menu variable, this will be used over and over



cout<<
"1.Fortune Teller."<<endl;
cout<<
"2.Stock Market Advicer."<<endl;
cout<<
"3.Quit."<<endl;
cin>>menu;
while(!= 3)
{

if (menu == 1)
{
cout<<
"Welcome to the Fortune Teller."<<endl;
cout<<
"Enter your question."<<endl;
cin>>question;

theNumber = 1 + rand() % 4;
if (theNumber == 1)
{
cout<<
"Yes,I believe so!"<<endl;
}
elseif (theNumber == 2)
{
cout<<
"No way."<<endl;

}
elseif (theNumber == 3)
{
cout<<
"Most likely, yes."<<endl;

}
elseif (theNumber == 4)
{
cout<<
"Try again tomorrow."<<endl;

}
}
elseif (menu == 2)
{
cout<<
"Welcome to the Stock Market Advicer."<<endl;
cout<<
"Enter your stocks."<<endl;
cin>>stock;
theStock = 1 + rand() % 3;
switch (theStock)
{
case 1:
cout<<
"You should definatly buy!"<<endl;

case 2:
cout<<
"Sell! Sell! Sell!"<<endl;

case 3:
cout<<
"Heck if I know. Go ask your stock broker."<<endl;
}
}

elseif( menu == 3)
{
}
}

system(
"PAUSE");
return 0;

}

Whenever I try to compile it, This is what It gives :

Code:


------ 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 ==========

Thanks to anyone who can help me.

xpi0t0s 24Jun2009 04:41

Re: Creating Menu system
 
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.

Nuja 24Jun2009 05:22

Re: Creating Menu system
 
Quote:

Originally Posted by xpi0t0s (Post 50356)
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.

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.

xpi0t0s 24Jun2009 12:42

Re: Creating Menu system
 
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.


All times are GMT +5.5. The time now is 01:46.