I'm new to Objective-C, and this is really my first program that is interactive. I've been learning for about 2 weeks now.
So, my question is: typically I've noticed when you have multiple scanf
's in a row, they each wait for input - however in this situation, where I ask for account owner name, and balance - it fires both NSLog
functions instead of waiting for the first input.
Here is my main:
int main(int argc, char* argV[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
bank *columbiaBank = [[bank alloc] init];
int iteration = 0;
while (true) {
int selection = 0;
NSLog(@"\n1. Add Account \n2. Remove Account \n3. Modify Account \nWhat would you like to do?:");
scanf("%i", &selection);
if (selection == 1) {
NSLog(@"\nEnter account owner:");
char accountOwner;
scanf("%c", &accountOwner);
NSLog(@"\nEnter opening balance:");
float openingBalance;
scanf("%f", &openingBalance);
// create and add new account
bankAccount *newAccount = [[bankAccount alloc] initWithProps:[NSString stringWithFormat:@"%c", accountOwner] :[NSString stringWithFormat:@"%i", iteration] :openingBalance];
[columbiaBank addAccount:newAccount];
[newAccount release];
NSLog(@"\nAccount successfully added!");
} else if (selection == 2) {
NSLog(@"\nEnter account id:");
int accountId;
scanf("%i", &accountId);
// remove account
[columbiaBank removeAccount:[NSString stringWithFormat:@"%i", accountId]];
NSLog(@"\nAccount successfully removed!");
} else if (selection == 3) {
NSLog(@"\nThe bank currently has %i accounts.", columbiaBank.totalAccounts);
NSLog(@"\nThe bank's current balance from all accounts is $%f", columbiaBank.totalBankBalance);
NSLog(@"\n-- Output of all account info --");
[columbiaBank printAccounts];
} else {
NSLog(@"You did not enter a valid action.");
}
iteration++;
}
[columbiaBank release];
[pool drain];
return false;
}