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