Objective-C Simple Menu

I'm trying to get this simple menu to work. Can anyone see why it

Page 1 of 1

0 Replies - 3081 Views - Last Post: 29 May 2007 - 09:45 PM Rate Topic: -----

#1 barnwillyb  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 108
  • Joined: 22-May 07

Objective-C Simple Menu

Posted 29 May 2007 - 09:45 PM

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);.

#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 - 02:40 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1