C Programming Absolute Beginner's Guide (3rd Edition)

(Romina) #1
192.41, 389.00, 229.67, 18.31, 59.54};
/* Interact with the user looking for a balance. */
printf("\n\n*** Customer Balance Lookup ***\n");
printf("What customer number do you need to check? ");
scanf(" %d", &idSearch);
/* Search to see that the customer ID exists in the array */
for (ctr=0; ctr<10; ctr++)
{
if (idSearch == custID[ctr])
{
found = 1;
break;
}
}
if (found)
{
if (custBal[ctr] > 100.00)
{
printf("\n** That customer's balance is $%.2f.\n",
custBal[ctr]);
printf(" No additional credit.\n");
}
else
{
printf("\n** The customer's credit is good!\n");
}
}
else
{
printf("** You must have typed an incorrect customer ID.");
printf("\n ID %3d was not found in list.\n", idSearch);
}
return(0);
}

This program’s attempted customer search has three possibilities:



  • The customer’s balance is less than $100.

  • The customer’s balance is too high (more than $100).

  • The customer’s ID is not even in the list.


Here are three runs of the program showing each of the three possibilities:


Click here to view code image


*** Customer Balance Lookup ***
What customer number do you need to check? 313
** The customer's credit is good!
***Customer Balance Lookup ***
What customer number do you need to check? 891
** You must have typed an incorrect customer ID.
Free download pdf