LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-14-2010, 02:59 PM   #1
pr0xibus
Member
 
Registered: Apr 2004
Location: Scotland
Distribution: Slackware
Posts: 215

Rep: Reputation: 44
c++ menu system


hi guys. been a long time since i done some programming think it was delphi back about 5 years ago but trying out c++ now. anyway

i want to create a simple program but the menu thing baffles me

i was some error checking which i THINK is the CASE and SWITCH not sure tho.

anyway

i would like to loop the menu and if someone presses i.e. "1" they goto the 1 procedure and then back to the menu and hopefully continue this until they quit. "wasnt very good at loops etc"

here is the code ive done all of it myself and most likely its wrong but woudl like to learn lol so if someone can point me in the right direction it would be very much appreciated

Code:

#include <iostream>
using namespace std;

int menuchoice;
int januarymm;
int februarymm;
int totalmm;


void choice1()
{
cout << "january";
cin.get();
}

void choice2()
{
cout << "february";
}

void choice3()
{
cout << "total";
}

void choice4()
{
	cout << "exit";
}

void main()
{
	cout << " Rainfall Calculator by Nathan Hawthorne ";
	cout << "\n";
	cout << " 1. january Rainfall ";
	cout << "\n";
	cout << " 2. February Rainfall ";
	cout << "\n";
	cout << " 3. Total Rainfall ";
	cout << "\n";
	cout << " 4. Quit ";
	cout << "\n";
	cin >> menuchoice;


	//************************************************************* error management
	switch (menuchoice)
	{
	case '1':
	case '2':
	case '3':
	case '4':
		cout << " Selection OK ";
		cin.get();
		break;
	default:
		cout << " Invalid Selection\n";
		cin.get();
		break;
	//************************************************************ error management
		
		
		if (menuchoice = '1')
			choice1();
		if (menuchoice = '2')
			choice2();
		if (menuchoice = '3')
			choice3();
		if (menuchoice = '4')
			choice4();


	}
}
 
Old 09-14-2010, 04:08 PM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
I'm sorry, but there are a number of errors here and it would be better to point you to a C++ tutorial like this one (I have no idea how good that tutorial actually is, but the C++ standard library reference on the same site is very good).

It would be best to get a thorough overview of the language if you've had such a long time off programming (and especially if it's a new language to you).
 
Old 09-14-2010, 04:15 PM   #3
pr0xibus
Member
 
Registered: Apr 2004
Location: Scotland
Distribution: Slackware
Posts: 215

Original Poster
Rep: Reputation: 44
Quote:
Originally Posted by JohnGraham View Post
I'm sorry, but there are a number of errors here and it would be better to point you to a C++ tutorial like this one (I have no idea how good that tutorial actually is, but the C++ standard library reference on the same site is very good).

It would be best to get a thorough overview of the language if you've had such a long time off programming (and especially if it's a new language to you).
that site is alot better than some i have been looking at cheers for that
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
System Menu for Slack13? linus72 Slackware 3 01-31-2010 11:55 AM
restructuring the menu system? gunnix Debian 4 01-30-2005 03:08 PM
MDK9.2 - Menu system is not quite right pete_bogg Mandriva 1 11-23-2003 07:34 AM
System/Application menu Roxy143 Linux - General 0 06-27-2003 10:57 PM
Menu system scripting Nelleh Linux - Newbie 2 08-16-2002 04:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration