Thread: Need help capitalizing characters in a strong

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    19

    Need help capitalizing characters in a strong

    I'm trying to get to where the first letter of each word of the "description" is a capital letter while the rest is a lower case letter. So far, I'm not even able to successfully get every letter lower case. What am I doing wrong?




    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<ctype.h>
    #include<string.h>
    
    
    #define STORE "Sierra Sporting Goods"
    #define MINPROD 1
    #define MAXPROD 9999
    #define MINTYPE 1
    #define MAXTYPE 5
    #define MINQUAN 1
    #define MAXQUAN 50
    #define MINCOST 5.00
    #define MAXCOST 900.00
    #define MINPRICE 6.00
    #define MAXPRICE 1000.00
    #define TRUE 1
    #define FALSE 0
    
    int menu(void);
    void add(void);
    int quit(void);
    void getstring(char entry[], char prompt[]);
    int getint(int min, int max, char msg[]);
    double getreal(double min, double max, char msg[]);
    double total(double t, double quantity);
    void show(int num, int product, int type, int quantity, double cost, double price, char description[]);
    void init_costs(double types[], int c);
    void show_costs(double types[], int c);
    char categories[][15] = {"", "Camping", "Tennis", "Golf", "Snow sports", "Water sports"};
    void strcase(char description[]);
    
    
    
    main()
    {
         int key, more = TRUE;
         do
        {
               key = menu();
               switch(key)
               {
                     case 1: add(); break;
                     case 2:
                     case 3:
                     case 4: printf("\nNot Implemented. Press Enter to Continue"); getchar(); break;
                     case 5: more = quit(); break;
                     default: printf("\nError in selection. Press Enter to Continue\a");
          getchar();
          }
    }
    while(more);
    return 0;
    }
    
    int menu()
    {
    system("cls");
    int selection;
    printf("%s\n\n\n", STORE);
    
              printf("1 = Add a record\n");
              printf("2 = Report\n");
              printf("3 = Delete a record\n");
              printf("4 = Change a record\n");
              printf("5 = Quit\n");
    
               /*For user selection*/
               printf("\n\nEnter your selection here: ");
               scanf("%d%*c", &selection);
    
    return(selection);
    }
    
    void add()
    {
         int n=0, product, type, quantity; /*Product is product number. Type is product type*/
         double cost, price, tprice; 
         char selection;
         char description[16];
    
         double types[6]; 
         
         init_costs(types, 6);
         
         do
         {
         system("cls");
         printf("%s\n\n\n", STORE);
         product = getint(MINPROD, MAXPROD, "Product Number");
         type = getint(MINTYPE, MAXTYPE, "Product Type");
         getstring(description, "Description:");
         quantity = getint(MINQUAN, MAXQUAN, "Product Quantity");   
         cost = getreal(MINCOST, MAXCOST, "Product Cost");
         price = getreal(MINPRICE, MAXPRICE, "Product Price");
         types[type] += cost;
         strcase(description);
         
         show(++n, product, type, quantity, cost, price, description);
         
         
         
         printf("\n\nDo you want to Continue? <Y or N>");
         scanf("%c%*c", &selection);     
              }
         while(selection == 'Y' || selection == 'y');
          
          
         system("cls");
         show_costs(types, 6); 
         printf("\nPress Enter to Continue"); 
         getchar();
    }
    
    void show(int n, int product, int type, int quantity, double cost, double price, char description[])
    {
         
    
         printf("\nTotal number of products> %d", n);
         printf("\nThe product number is --> %.4d", product);
         printf("\nThe product type is ----> %d", type);
         printf("\nThe Description is -----> %s", description);
         printf("\nThe quantity is --------> %d", quantity);
         printf("\nThe cost is ------------> %.2f", cost);
         printf("\nThe price is -----------> %.2f", price);
         printf("\nThe total price is -----> %.2f", total(price, quantity));
         printf("\nThe total cost is ------> %.2f", total(cost, quantity));
         
    }
    
    int getint(int min, int max, char item[])
    {
        int n;
        printf("Enter the %s %d to %d: ", item, min, max);
        scanf("%d%*c", &n);
        while (n < min || n > max)
          {
               printf("\nRange Error.\a");
               printf("\nEnter the %s %d to %d: ", item, min, max);
               scanf("%d%*c", &n);
          }
    return(n);
    }
    
    
    
    double getreal(double min, double max, char item[])
    {
           double n;
    printf("Enter the %s %.2f to %.2f: ", item, min, max);
    scanf("%lf%*c", &n);
    while(n < min || n > max)
            {
            printf("\nRange Error.\a");
            printf("\nEnter the %s %.2f to %.2f: ", item, min, max);
            scanf("%lf%*c", &n);
            }
    return (n);
    }
    
    
    
    double total(double t, double quantity)
    {
          return(quantity*t);
    }
    
    
    
    int quit()
    {
    printf("\nPress Enter to Continue");
    getchar();
    return 0;
    }
    
    
    
    void init_costs(double types[], int c)
    {
         int i;
         
         for(i=1; i<c; i++)
         types[i] = 0;
    }         
    
    void show_costs(double types[], int c)
    {
         int i;
         
         printf("%s\n\n\n", STORE);
         printf("Product Cost by Type");
         printf("\n\nType_______Category_______Cost\n\n");
         for(i=1; i<c; i++)
         {
         printf("%d%18s%10.2lf\n", i, categories[i], types[i]);
    }
    }
    
    void getstring(char entry[], char prompt[])
    {
         printf("Enter the %s", prompt);
         gets(entry);
    }
    
    void strcase(char description[])
    {
         int i;
         
          for (i = 0; i < strlen(description); i++)
    	{
    		description[i] = tolower(description[i]);
    	}
          gets(description);
    }
    Last edited by zbred; 03-25-2011 at 04:35 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Replies: 2
    Last Post: 09-16-2009, 06:00 AM
  3. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  4. How do you check how many characters a user has entered?
    By engstudent363 in forum C Programming
    Replies: 5
    Last Post: 04-08-2008, 06:05 AM
  5. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM