Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Calc.h file:
- #import <Foundation/Foundation.h>
- #import <Foundation/NSString.h>
- #import <Cocoa/Cocoa.h>
- int tGlobalVar = 0;
- int xGlobalVar = 0;
- int gGlobalVar = 0;
- @interface Calc : NSObject
- {
- IBOutlet NSTextField *answer;
- IBOutlet NSTextField *a;
- IBOutlet NSTextField *b;
- IBOutlet NSTextField *c;
- IBOutlet NSTextField *percent;
- IBOutlet NSTextField *x;
- IBOutlet NSTextField *g;
- }
- -(IBAction) answer: (id) sender;
- //-(IBAction) right: (id) sender;
- -(IBAction) wrong: (id) sender;
- -(IBAction) clearAll: (id) sender;
- -(IBAction) multiply: (id) sender;
- @end
- // Calc.m file:
- #import "Calc.h"
- @implementation Calc
- -(IBAction) multiply: (id) sender
- {
- NSInteger buttonTitle = [sender tag];
- [answer setIntegerValue: buttonTitle];
- }
- -(IBAction) answer: (id) sender
- {
- int aAnswer, bAnswer, cAnswer, result;
- aAnswer = [a intValue];
- bAnswer = [b intValue];
- cAnswer = [c intValue];
- result = aAnswer * bAnswer;
- if (cAnswer != result)
- {
- ++tGlobalVar;
- ++xGlobalVar;
- [x setIntValue: xGlobalVar];
- }
- else if ((cAnswer == result) && (cAnswer != 0))
- {
- ++tGlobalVar;
- ++gGlobalVar;
- [g setIntValue: gGlobalVar];
- }
- }
- -(IBAction) clearAll: (id) sender
- {
- [a setIntValue: 0];
- [b setIntValue: 0];
- [c setIntValue: 0];
- [answer setIntValue: 0];
- gGlobalVar = gGlobalVar - gGlobalVar;
- [x setIntValue: gGlobalVar];
- xGlobalVar = xGlobalVar - xGlobalVar;
- [g setIntValue: gGlobalVar];
- NSString *wrongValue = @"Please enter a value to begin";
- [percent setStringValue: wrongValue];
- }
- -(IBAction) wrong: (id) sender
- {
- float num, denum, result;
- num = [x floatValue];
- denum = (float) tGlobalVar;
- result = (num/denum)*100.0;
- if (xGlobalVar == 0 && gGlobalVar == 0)
- {
- NSString *wrongValue = @"You must first compute to begin.";
- [percent setStringValue: wrongValue];
- }
- else if (xGlobalVar == 0 && gGlobalVar != 0)
- {
- NSString *wrongValue = @"You have 100% correct.";
- [percent setStringValue: wrongValue];
- }
- else if (xGlobalVar != 0 && gGlobalVar == 0)
- {
- NSString *wrongValue = @"You have 100% incorrect.";
- [percent setStringValue: wrongValue];
- }
- else if (xGlobalVar != 0 && gGlobalVar != 0)
- {
- NSString *wrongValue = [NSString stringWithFormat: @"The amount you have wrong is %.1f%%", result];
- [percent setStringValue: wrongValue];
- }
- }
- @end
Add Comment
Please, Sign In to add comment