Welcome to Dream.In.Code
Become an Expert!

Join 149,514 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,337 people online right now. Registration is fast and FREE... Join Now!




Objective-C Simple Menu

 
Reply to this topicStart new topic

Objective-C Simple Menu, I'm trying to get this simple menu to work. Can anyone see why it

barnwillyb
29 May, 2007 - 08:45 PM
Post #1

D.I.C Head
**

Joined: 22 May, 2007
Posts: 55


My Contributions
I'm trying to get this simple menu to work. Can anyone see why it is not working. I am trying to get the default to work if I answer with 5.

I see where my problem was—it is in the scanf statement( scanf("%i", choice); ). Should be: scanf("%i", &choice);.

CODE
#import <objc/Object.h>
#import <stdio.h>


@interface Menu : Object
{
    int choice;
}

-(void) display;
-(int) choose;

@end

#import "Menu.h"


@implementation Menu;

// DISPLAY A SIMPLE MENU
-(void) display
{
    printf ("\nCLASS OPTIONS\n");
    printf ("  1. Enter Student Scores\n");
    printf ("  2. Compute Class Average\n");
    printf ("  3. Show Student Grades\n");
    printf ("  4. Show Student Scores\n");
    printf ("  9. Quit\n");
}

// CHOOSE OPTIONS FROM A SIMPLE MENU
-(int) choose
{
    printf ("Class Choice: ");
        scanf("%i", choice);

    return choice;
}

@end

#import <Cocoa/Cocoa.h>

#import "Menu.h"

int main(int argc, char *argv[])
{
    Menu *theMenu = [[Menu alloc] init];
    int menuChoice = 0;
    
    while (menuChoice != 9) {
        [theMenu display];
        //theMenu->display();
        menuChoice = [theMenu choose];
        //menuChoice = theMenu->choose();
        
        switch (menuChoice) {
            case '1': enter_student_scores(); break;
            case '2': display_class_average(); break;
            case '3': display_student_grades(); break;
            case '4': display_student_scores(); break;
            case '9': display_copyright(); break;
            default: printf ("\n\aUNRECOGNIZED MENU OPTION!");
        }
    }
    [theMenu release];
    
    return 0;
}


This post has been edited by NickDMax: 31 May, 2007 - 01:40 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 07:58PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month