training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

promptletter.c (1821B)


      1 /* Exercise 8.41 */
      2 
      3 #include <stdio.h>
      4 #include <string.h>
      5 #include <stdlib.h>
      6 
      7 #define BUF 30
      8 #define SIZE 8
      9 
     10 void prompt(const char * const debitor,
     11             const char * const address,
     12 	    const char * const account,
     13 	    const double money, const int delay);
     14 
     15 int main(void)
     16 {
     17    char debitor[BUF], address[BUF], account[SIZE], money[SIZE];
     18    int delay;
     19 
     20    printf("Debitor's (name and surname): ");
     21    gets(debitor);
     22 
     23    printf("Debitor's address: ");
     24    gets(address);
     25 
     26    printf("Account number: ");
     27    gets(account);
     28 
     29    printf("Due money: ");
     30    gets(money);
     31 
     32    printf("How many months of delay: ");
     33    scanf("%d", &delay);
     34 
     35    prompt(debitor, address, account, atof(money), delay);
     36 
     37    return 0;
     38 } /* E0F main */
     39 
     40 
     41 void prompt(const char * const debitor,
     42             const char * const address,
     43 	    const char * const account,
     44 	    const double money, const int delay)
     45 {
     46    printf("\n----- Letter [%d] -----\n\n", delay >= 5 ? 5 : delay);
     47    switch(delay >= 5 ? 5 : delay) {
     48       case 1:
     49 	 printf("Hello %s,\n\t"
     50 		"we are writing to you because you have one month of delay\n"
     51 		"in the payment of our products. Please, it supplies first\n"
     52 		"possible! We remember you some data stuff:\n\n"
     53 		"\tYour account number: %s\n"
     54 		"\tYour address: %s\n"
     55 		"\tQuantity to pay: %.2f\n"
     56 		"\n"
     57 		"We are waiting for your reply, in the while give you\n",
     58 		debitor, account, address, money);
     59 	 break;
     60       case 2:
     61 	 printf("Letter.. (priority low)\n");
     62 	 break;
     63       case 3:
     64 	 printf("Letter.. (priority medium)\n");
     65 	 break;
     66       case 4:
     67 	 printf("Letter.. (priority high)\n");
     68 	 break;
     69       case 5:
     70 	 printf("Letter.. (priority very high)\n");
     71 	 break;
     72    }
     73    printf("\nBest regards\n\nClaudio M. corporation\n12534, Madison DC\nbla..\n");
     74    printf("\n----- End letter -----\n");
     75 
     76 } /* eof prompt() */
     77