Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 10-18-2006, 05:14 AM   #1 (permalink)
krisl100
krisl100
 
Join Date: Oct 2006
Location: Montreal
Posts: 34
krisl100 is on a distinguished road
simple menu

Found a simpler way of building a menu & I also want to seperate it into its own function, I have done some of it, I wanted to build the menu first, but I keep getting an undeclared identifier error, then a redefinition error, please take a look at my code, here is the code:

// krisleblanc3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
#include "iomanip"
#include "conio.h"
using namespace std;

int menu();


int _tmain(int argc, _TCHAR* argv[])
{


cout << " Main function enetered later. ";





getch();
return 0;
}

int menu()
{
char choice;

do
{
choice = toupper(display_menu());

switch (choice)
{
case 'A':
cout << "Please enter a positive whole number: " << endl;
break;

case 'B':
cout << "Please enter the number of days you will work: " << endl;
break;

case 'C':
cout << "Enter a letter: " << endl;
break;

case 'X':
break;

default:
cout << endl << "\a Invalid choice -- try again" << endl;
}

} while (choice != 'X');

return 0;

}

char display_menu()
{
char choice;

cout << endl << endl;
cout << " MAIN MENU" << endl;
cout << "A. Please enter a positive whole number: " << endl;
cout << "B. Please enter the number of days you will work: " << endl;
cout << "C. Enter a letter: " << endl;
cout << "X. Exit" << endl;
cout << "Make a choice: ";
cin >> choice;
return choice;

}
krisl100 is offline   Reply With Quote
Old 10-18-2006, 01:20 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
1) In menu() you refer to display_menu yet you never declared menu in advance. You should have.
2) Use <cctype> for toupper(). The ISO standard requires it. The fact that Visual Studio 2005 doesn't generate a warning or error is compiler-specific (formally: implementation specific). You must use it anyway.

Code:
#include <iostream>
#include <cctype>

using namespace std;

int menu();
char display_menu();

int main()
{
  menu();

  cin.get();
  return 0;
}

int menu()
{
  char choice;

  do
  {
    choice = toupper(display_menu());

    switch (choice)
    {
    case 'A':
      cout << "Please enter a positive whole number: " << endl;
      break;

    case 'B':
      cout << "Please enter the number of days you will work: " << endl;
      break;

    case 'C':
      cout << "Enter a letter: " << endl;
      break;

    case 'X':
      break;

    default:
      cout << endl << "\a Invalid choice -- try again" << endl;
    }

  } while (choice != 'X');

  return 0;

}

char display_menu()
{
  char choice;

  cout << endl << endl;
  cout << " MAIN MENU" << endl;
  cout << "A. Please enter a positive whole number: " << endl;
  cout << "B. Please enter the number of days you will work: " << endl;
  cout << "C. Enter a letter: " << endl;
  cout << "X. Exit" << endl;
  cout << "Make a choice: ";
  cin >> choice;
  return choice;

}
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Menu krisl100 Standard C, C++ 10 10-17-2006 09:23 AM
menu script help benzspida PHP 0 07-15-2006 12:48 PM
daily menu script mchit PHP 9 07-25-2005 12:35 PM
Problems with very simple VC++ Feis Platform/API C++ 1 06-24-2005 04:28 PM
layout menu form buchannon HTML, XML, Javascript, AJAX 7 11-09-2004 12:08 PM


All times are GMT -8. The time now is 06:17 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting