Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gizabo

macrumors regular
Original poster
Jul 20, 2008
124
0
This is so weird... I would think this would work... but it just doesnt....

Anybody understand why?

Code:
//
//  AppController.m
//  Right N' Wrong
//
//  Created by Daniel Kindler on 4/4/09.
//  Copyright 2009 Stdio.H. All rights reserved.
//

#import "AppController.h"
@implementation AppController

- (void) updateScore {
	double percentScore = 100.0 * varRight / (varWrong + varRight);
	[percentCorrect setStringValue:[NSString stringWithFormat:@"%.1f%%", percentScore]];
}

- (void)correctAns {
	[numberRight setStringValue:[NSString stringWithFormat:@"%i Correct", varRight]];
}

-(void)wrongAns {
	[numberWrong setStringValue:[NSString stringWithFormat:@"%i Incorrect", varWrong]];
}


- (IBAction)reset:(id)sender; {
	varRight = 0;
	varWrong = 0;
	[self wrongAns];
	[self correctAns];
	[percentCorrect setStringValue:[NSString stringWithFormat:@"0.0%%"]];
}


- (IBAction)right:(id)sender; {
	varRight++;
	[self correctAns];
	[self updateScore];
}

- (IBAction)wrong:(id)sender; {
	varWrong++;
	[self wrongAns];
	[self updateScore];
}

- (IBAction)subOneRight:(id)sender {
	varRight - 1;
	[self correctAns];
	[self updateScore];
}


- (IBAction)subOneWrong:(id)sender {
	varWrong - 1;
	[self wrongAns];
	[self updateScore];

}

@end



Do you see the part at the end were it says:
Code:
- (IBAction)subOneRight:(id)sender {
	varRight - 1;
	[self correctAns];
	[self updateScore];
}


- (IBAction)subOneWrong:(id)sender {
	varWrong - 1;
	[self wrongAns];
	[self updateScore];

}


why doesnt that work... Im trying to get varRight and varWrong to get subtracted by one... Why wont it work?
 

larkost

macrumors 6502a
Oct 13, 2007
534
1
Code:
varRight - 1;

varWrong - 1;

why doesnt that work... Im trying to get varRight and varWrong to get subtracted by one... Why wont it work?

You are just subtracting the value, but not storing it. You would need something like this:

Code:
varRight = varRight--;
or
Code:
varRight = varRight -1;
 

gizabo

macrumors regular
Original poster
Jul 20, 2008
124
0
thanks... And why doesnt this work?

Code:
- (IBAction)subOneRight:(id)sender {
	for (varRight >= 0 ) {
		varRight--;
		[self correctAns];
		[self updateScore];
	}
}
 

eddietr

macrumors 6502a
Oct 29, 2006
807
0
Virginia
thanks... And why doesnt this work?

Code:
- (IBAction)subOneRight:(id)sender {
	for (varRight >= 0 ) {
		varRight--;
		[self correctAns];
		[self updateScore];
	}
}

Did you mean to create a for loop there?

I really think you would be doing yourself a huge favor if you learned some basic C (or even Python or Ruby or something) before you try to get too deep into Obj-C and Cocoa.

There's a lot to be said for learning to walk before you run, you know?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.