Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,829 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,846 people online right now. Registration is fast and FREE... Join Now!




menu in C++

 
Reply to this topicStart new topic

menu in C++, In C++, is it possible to move the cursor while in DOS(output) mode?

dan_ram
4 Oct, 2008 - 04:40 AM
Post #1

D.I.C Head
**

Joined: 15 Aug, 2007
Posts: 76


My Contributions
i'm creating a kind of a menu with a number of options. is it possible to move the cursor and select the desired option? the option should be like a link to something else. if possible, what function should i use? else, any other alternatives? can you also give me some websites where the built in library functions of C++ are available?

User is offlineProfile CardPM
+Quote Post

csmanoj
RE: Menu In C++
4 Oct, 2008 - 05:18 AM
Post #2

D.I.C Head
Group Icon

Joined: 6 Aug, 2007
Posts: 142



Thanked: 3 times
Dream Kudos: 50
My Contributions
You would then travel into the subject of event driven programming. That's a pretty big leap if you've just begun to learn C/C++. You can see this link for a nice tutorial on accessing mouse in dos mode - http://www.geocities.com/rk_page/
User is offlineProfile CardPM
+Quote Post

JackOfAllTrades
RE: Menu In C++
4 Oct, 2008 - 05:54 AM
Post #3

Cantankerous Old Fart
Group Icon

Joined: 23 Aug, 2008
Posts: 597



Thanked: 60 times
Dream Kudos: 50
My Contributions
CPP Reference
cplusplus.com
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Menu In C++
4 Oct, 2008 - 07:28 AM
Post #4

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,040



Thanked: 106 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
Well, I guess the good news is it's NOT event programming, not even a little. Menus are the antithesis of an event driven program, actually.

The bad news is it's not possible in a standard way. C++ treats user IO as a stream and it's not real particular about it. In this way, it is OS agnostic. So, if you need to do things like move a cursor around the screen or process a single key press, you need an OS specific solution.

For Windows it's usually conio.h, for *nix flavors it's usually the cursor libs. At this point, you may wish to ask yourself if you really want a console application or a windows based one. wink2.gif

User is offlineProfile CardPM
+Quote Post

dan_ram
RE: Menu In C++
5 Oct, 2008 - 08:06 AM
Post #5

D.I.C Head
**

Joined: 15 Aug, 2007
Posts: 76


My Contributions
QUOTE
For Windows it's usually conio.h, for *nix flavors it's usually the cursor libs. At this point, you may wish to ask yourself if you really want a console application or a windows based one.

i'm sorry but i couldn't understand what you said.. blink.gif
i dont think i can do so much as menu is just a small part of my project.

can anyone suggest any way of presenting the menu?
one way i know is to ask the user to enter the corresponding serial number of the option;but its too vague when it comes to a project. so any other method?

This post has been edited by dan_ram: 5 Oct, 2008 - 08:09 AM
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Menu In C++
5 Oct, 2008 - 11:35 AM
Post #6

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,040



Thanked: 106 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
Here's an example of a very simple menu. No highlights, nothing special, just asking the user for input. You can have menus call menus. Display different data based on what the user responds with, etc.

A menu is a tool. When you ask "is it possible to move the cursor" you're defining the specification of the tool. I seems that your question really is, "how do I present a list of options to the user and process their response." If so, hopefully this will help.

cpp

#include <iostream>
using namespace std;

// we return whether the menu was processed correctly
bool processMenu() {
// show the user the menu
cout << "Main Menu" << endl;
cout << "Select your favorite food" << endl;
cout << "1. Cheese Burger" << endl;
cout << "2. Ramen" << endl;
cout << "3. Mashed Potatos" << endl;

// get the response
char choice;
cin >> choice;

// process the response
// do something for each valid option
if (choice=='1') {
cout << "Hold the pickle, hold the lettuce." << endl;
} else if (choice=='2') {
cout << "Yum, with extra naruto." << endl;
} else if (choice=='3') {
cout << "Don't forget the gravy." << endl;
} else {
// if we got this far, the response was not valid
return false;
}
return true;
}

int main () {
// we loop until the menu is processed
while (!processMenu()) {
// if we get here, the menu was not processed correctly
// so we bother them some more
cout << "Sorry, that is not a valid choice." << endl;
cout << "Please try again." << endl << endl << endl;
}
cout << endl << "Thank you for playing." << endl;
return 0;
}


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 03:42PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month