Note that there are some explanatory texts on larger screens.

plurals
  1. POscanf is not waiting for input within my loop?
    text
    copied!<p>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.</p> <p>So, my question is: typically I've noticed when you have multiple <code>scanf</code>'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 <code>NSLog</code> functions instead of waiting for the first input.</p> <p>Here is my main:</p> <pre><code>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", &amp;selection); if (selection == 1) { NSLog(@"\nEnter account owner:"); char accountOwner; scanf("%c", &amp;accountOwner); NSLog(@"\nEnter opening balance:"); float openingBalance; scanf("%f", &amp;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", &amp;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; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload