Thread: Coding help.... have a few questions

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Cess's Avatar
    Join Date
    Sep 2011
    Posts
    55

    Coding help.... have a few questions

    I am having a lot of trouble with this program, I've tried adding and changing things but I think I'm making it worst.
    My 1st problem is the program seems to end after imputing the 1st values.... It didn't do that before... I need it to take in values and out put which values are negative, odd, and zero. However I can't do that if the program ends after the users 1st input... I'm guessing its an ; or bracket problem that I couldn't find

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    /* Homework Create a program that accepts user input and store a set of integers in one for loop,
     a set of double values in a second for loop and a set of characters in a character string.
     Then the program will count the number of positive, zero and negative values for the integer 
    and double arrays and the number of upper and lower case variables in the character string. 
    
    In other words it needs to:
    The program is just to count the number of positive, negative and zero
    values that a user enters. In the first case, the user enters integers
    and then real values are entered. A character string is then entered
    and the program counts upper and lower case characters.*/
    
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
    
        int intarray[10];
        double doublearray[10];
        char string[20];
        int uppercount = 0, lowercount = 0;
        int i;
        int numints, numdoubles;
        int negcount, poscount, zerocount;
    
        printf("Input number of integer values: ");
        scanf("%d", &numints);
        for (i=0; i< numints; i++)
        {
            printf("Enter an integer value: ");
            scanf("%d", &intarry[i]);
        }
        /* Then ask for number of double values and read them in using %lf */
        printf("Input a another value:  ");
        scanf("%lf", &numdoubles);
        for (i=0; i< numdoubles; i++)
    
        {
            printf("Enter an integer value: ");
            scanf("%lf", &doublearray[i]);
        }
    
        /* #3 */
        printf("Enter a short character string: ");
        scanf("%s", string);
        negcount=0;/* initialize the counters*/
        poscount=0;
        zerocount=0;
        for (i = 0; i < numints; i++)
        {
            if (intarray[i] < 0)
                negcount++;
            printf("You entered %d negtive values ",negcount);
    
            if (intarray[i] == 0)
                zerocount++;
            printf("You entered %d zero values ",zerocount);
    
            if (intarray[i] > 0)
                poscount++;
            printf("You entered %d postive values",poscount);
        }
    
       /* print out counter values */
       printf("Enter a short character string: ");
        scanf("%s", string);
        negcount=0;/* initialize the counters*/
        poscount=0;
        zerocount=0;
        /* Do counts for double array */
        for (i = 0; string[i]; i++)
        {
            if ((string[i] >= 'A') && (string[i] <= 'Z'))
                uppercount++;
                printf("You have %d upper case characters\n",uppercount);
    
            if ((string[i] >= 'a') && (string[i] <= 'z'))
                lowercount++;
                printf("You have %d lower case characters\n",lowercount);
        }
       /* print out counter values etc.....*/
    
        system("Pause");
        return 0;
    }
    thanks for any help!!!
    Last edited by Cess; 10-03-2011 at 09:10 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IDE for vlc coding
    By binnyshah in forum Windows Programming
    Replies: 2
    Last Post: 07-06-2010, 02:56 AM
  2. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  3. Coding a log in.....
    By Darkozuma in forum C++ Programming
    Replies: 5
    Last Post: 07-20-2008, 07:55 PM
  4. C coding questions
    By vopo in forum C Programming
    Replies: 3
    Last Post: 08-29-2007, 02:37 AM
  5. coding.
    By programer9000 in forum C++ Programming
    Replies: 2
    Last Post: 01-30-2003, 08:59 PM