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!!!